Greasy Fork 还支持 简体中文。

切换标题显示

切换网页标题、网址和网址域名的显示

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         切换标题显示
// @namespace    http://tampermonkey.net/
// @version      0.6.1
// @description  切换网页标题、网址和网址域名的显示
// @author       You
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @run-at       document-start
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    let displayMode = GM_getValue('displayMode') || 'title';
    const originalTitle = document.title;

    function switchDisplayMode() {
        switch (displayMode) {
            case 'title':
                document.title = window.location.href;
                displayMode = 'url';
                break;
            case 'url':
                document.title = getUrl();
                displayMode = 'hostname';
                break;
            case 'hostname':
                document.title = originalTitle;
                displayMode = 'title';
                break;
            default:
                break;
        }
        GM_setValue('displayMode', displayMode);
    }

    function getUrl() {
        try {
            return new URL(window.location.href).hostname;
        } catch (error) {
            console.error('Error getting URL:', error);
            return window.location.href;
        }
    }

    GM_registerMenuCommand('➥切换标题显示', switchDisplayMode);

    window.addEventListener('load', function() {
        switch (displayMode) {
            case 'url':
                document.title = window.location.href;
                break;
            case 'hostname':
                document.title = getUrl();
                break;
            default:
                break;
        }
    });

    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = originalTitle;
        } else {
            switch (displayMode) {
                case 'url':
                    document.title = window.location.href;
                    break;
                case 'hostname':
                    document.title = getUrl();
                    break;
                default:
                    break;
            }
        }
    });

})();