Google Timer Title Update

Automatically updates the title when using Google's timer

目前为 2016-09-02 提交的版本。查看 最新版本

// ==UserScript==
// @name           Google Timer Title Update
// @namespace      org.alorel.googletimer
// @author         Alorel <[email protected]>
// @description    Automatically updates the title when using Google's timer
// @include        https://*google.*/search?*
// @version        1.0
// @icon           https://cdn.rawgit.com/AlorelUserscripts/google-timer-title-switcher/master/icon.png
// @run-at         document-end
// @grant          GM_info
// ==/UserScript==

(function (document, MutationObserver) {
    var timerArea,
        container,
        title;

    if (container = document.querySelector("#act-timer-section>div")) {
        timerArea = container.querySelector("div");
        title = document.querySelector("head>title");

        (function () {
            var faviconElement;
            if (faviconElement = document.querySelector('link[rel="shortcut icon"]')) {
                faviconElement.setAttribute("href", GM_info.script.icon);
                faviconElement = null;
            }
        })();

        (new MutationObserver(function () {
            if (container.classList.contains("act-tim-paused")) {
                title.innerText = "PAUSED";
            } else if (container.classList.contains("act-tim-finished")) {
                title.innerText = "FINISHED";
            } else {
                title.innerText = timerArea.innerText.trim();
            }
        })).observe(timerArea, {
            childList: true,
            attributes: true,
            characterData: true,
            subtree: true
        });
    }
})(document, MutationObserver);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址