Greasy Fork

Greasy Fork is available in English.

自定义网页标题

2024/3/19 11:23:41

当前为 2024-06-03 提交的版本,查看 最新版本

// ==UserScript==
// @name        自定义网页标题
// @namespace   Violentmonkey Scripts
// @match       https://m.ithome.com/*
// @match       https://web.telegram.org/*
// @match       https://bbs.nga.cn/*
// @match       https://bbs.hupu.com/*
// @match       https://*.yahoo.co.jp/*
// @match       https://v2ex.com/*
// @match       https://www.reddit.com/*
// @grant       none
// @version     1.6.2
// @author      hoorn
// @icon        https://s2.loli.net/2024/05/29/m5LcD7ZblIrQHXV.png
// @description 2024/3/19 11:23:41
// @license     GPL-3.0 License
// ==/UserScript==
(function () {
    'use strict';
    var currentHost = window.location.host;

    //Modify the title
    var pageTitle = document.querySelector('title');
    pageTitle.textContent = '.';

    //Modify the image
    var imageUrl = 'https://s2.loli.net/2024/05/29/m5LcD7ZblIrQHXV.png';
    pageTitle.textContent = '.';

    if (currentHost.startsWith('www.yahoo.co.jp')
        || currentHost.startsWith('news.yahoo.co.jp')
        || currentHost.startsWith('v2ex.com')
        || currentHost.startsWith('bbs.hupu.com')
    ) {
        var iconlink = document.querySelector('link[rel="icon"]');
        if (iconlink) {
            iconlink.href = imageUrl;
        }
        var shortIconLink = document.querySelector('link[rel="shortcut icon"]');
        if (shortIconLink) {
            shortIconLink.href = imageUrl;
        }
    } else if (currentHost.startsWith('www.reddit.com')) {
        var existingIcons = document.querySelectorAll('link[rel="icon"], link[rel="shortcut icon"]');
        existingIcons.forEach(function (icon) {
            icon.parentNode.removeChild(icon);
        });

        var icons = [
            { href: imageUrl, sizes: "64x64" },
            { href: imageUrl, sizes: "128x128" },
            { href: imageUrl, sizes: "192x192" }
        ];
        icons.forEach(function (icon) {
            var link = document.createElement('link');
            link.setAttribute('rel', 'icon shortcut');
            link.setAttribute('sizes', icon.sizes);
            link.setAttribute('href', icon.href);
            document.head.appendChild(link);
        });
    }
    else {
        var linkElement = document.querySelector('link[rel="icon"]');
        if (linkElement) {
            linkElement.href = imageUrl;
        }
        var favicon = document.querySelector('link[rel="alternate icon"]');
        if (favicon) {
            favicon.href = imageUrl
        }
    }
})();