最近访问的标签

标签页失去焦点后,显示30s的倒计时,方便快速定位。

// ==UserScript==
// @name         最近访问的标签
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  标签页失去焦点后,显示30s的倒计时,方便快速定位。
// @author       Lucas
// @match        https://**/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let title;
    let intervalId;

    // 当窗口失去焦点时触发
    window.onblur = function() {

        let count = 30;
        title = document.title;
        document.title = `${count}-${title}`;

        intervalId = setInterval(() => {

            count--;
            document.title = `${count}-${title}`;

            // 当计数减到0时,清除定时器并恢复原始标题
            if (count <= 0) {
                clearInterval(intervalId);
                document.title = title;
            }
        }, 1000);
    };

    // 当窗口获得焦点时恢复原始标题
    window.onfocus = function() {
        clearInterval(intervalId);
        document.title = title ? title : document.title;
    };

})();

QingJ © 2025

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