ESJ Zone: Unify Domain Names

Unify internal links to use the current mirror.

当前为 2024-02-14 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name               ESJ Zone: Unify Domain Names
// @name:zh-TW         ESJ Zone:統一域名
// @description        Unify internal links to use the current mirror.
// @description:zh-TW  統一內部連結使用目前鏡像站點。
// @icon               https://icons.duckduckgo.com/ip3/www.esjzone.cc.ico
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            1.0.0
// @license            MIT
// @match              https://www.esjzone.cc/*
// @match              https://www.esjzone.me/*
// @run-at             document-end
// @grant              none
// ==/UserScript==

(async function ()
{
    const WHITELISTED_HOSTNAMES = ["www.esjzone.cc", "www.esjzone.me"];

    function handleAnchor(anchor)
    {
        if (!anchor.href) { return false; }

        const url = new URL(anchor.href);
        if (!WHITELISTED_HOSTNAMES.includes(url.hostname)) { return false; }

        if (url.hostname !== location.hostname)
        {
            url.hostname = location.hostname;
            anchor.href = url.href;

            return true;
        }

        return false;
    }

    async function handleAnchorAsync(anchor)
    {
        return handleAnchor(anchor);
    }

    const results = await Promise.all(Array.from(document.getElementsByTagName("a")).map(handleAnchorAsync));
    console.debug(`Updated ${results.reduce((last, result) => (last + result), 0)} URL(s).`);
})();