Return Google Search Counter

Brings back the Google search counter

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Return Google Search Counter
// @author       NWP
// @description  Brings back the Google search counter
// @namespace    https://greasyfork.org/users/877912
// @version      0.1
// @license      MIT
// @include      https://www.google.*/search*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const debug = false;

    function log(message, data) {
        if (debug) {
            if (data !== undefined && data !== null) {
                console.log(message, data);
            } else {
                console.log(message);
            }
        }
    }

    function relocateResultStats(observer) {
        const resultStats = document.getElementById('result-stats');
        const appbar = document.getElementById('appbar');

        log(resultStats ? "Found resultStats:" : "resultStats not found.", resultStats);
        log(appbar ? "Found appbar:" : "appbar not found.", appbar);

        if (!resultStats || !appbar) {
            log("One or both elements (resultStats, appbar) not found. Stopping observer.");
            observer.disconnect();
            return;
        }

        if (!appbar.contains(resultStats)) {
            log("Appending resultStats to appbar.");
            try {
                appbar.appendChild(resultStats);
                log("Stopping observer as the task is complete.");
                observer.disconnect();
            } catch (e) {
                console.error("Error appending resultStats to appbar:", e);
            }
        } else {
            log("resultStats is already in the appbar, stopping observer.");
            observer.disconnect();
        }
    }

    const observer = new MutationObserver(() => {
        log("MutationObserver detected changes in the DOM.");
        relocateResultStats(observer);
    });

    log("Starting MutationObserver.");
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    log("Performing initial check.");
    relocateResultStats(observer);

})();