[F2] Reset Page Title

Press F2 to reset the tab title

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name                [F2] Reset Page Title
// @name:zh-CN          [F2] 重设页面标题
// @description         Press F2 to reset the tab title
// @description:zh-CN   按F2重新设置标签页标题

// @author              Moshel
// @namespace           https://hzy.pw
// @supportURL          https://github.com/h2y/link-fix
// @license             GPL-3.0

// @version      1.0.0
// @match        http://*/*
// @match        https://*/*
// @grant        none
// @run-at       document-body
// @require      https://cdn.staticfile.org/keymaster/1.6.1/keymaster.min.js
// ==/UserScript==

(function() {
    'use strict';

    let defaultTitle = document.title;
    let title = sessionStorage.getItem('title_by_userscript');
    let intervalID = null;
    if (title) {
        startInterval(title);
    }

    function startInterval(newTitle) {
        title = newTitle;
        sessionStorage.setItem('title_by_userscript', newTitle);
        document.title = newTitle;
        if (!intervalID) {
            intervalID = setInterval(() => {
                document.title = title;
            }, 6666);
        }
    }

    key("f2", _ => {
        let newTitle = prompt('请为页面设置一个标题', title ? title : document.title);
        if (newTitle) {
            startInterval(newTitle);
        } else {
            clearInterval(intervalID);
            intervalID = null;
            document.title = defaultTitle;
        }
    });
})();