Append Hostname to Window Title

Append the domain name of the site to the window title. Helps offer a hint to tools like AHK so that they can identify the site loaded.

当前为 2024-11-08 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Append Hostname to Window Title
// @namespace    https://greasyfork.org/users/77886
// @version      0.4
// @description  Append the domain name of the site to the window title. Helps offer a hint to tools like AHK so that they can identify the site loaded.
// @author       muchtall
// @include      *://*/*
// @match        *://*/*
// @grant        none
// ==/UserScript==

(
  function() {
    'use strict';

    /// Set the window title on page load
    window.addEventListener('load', function () {
      document.title = document.title + " - (" + window.location.hostname + ")";
    });

    // Workaround to sites that insist on changing the title of the window after the page loads
    setTimeout(function() {
        var target = document.querySelector('title');
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                var re = new RegExp(" - \\(" + window.location.hostname + "\\)$", "");
                if ( ! re.test(document.title) ) {
                  console.log('Title before "%s"', document.title);
                  document.title = document.title + " - (" + window.location.hostname + ")";
                  console.log('Title after "%s"', document.title);
                }
            });
        });
        var config = {
            childList: true,
        };
        observer.observe(target, config);
    }, 100);
  }
)();