ESJ Zone:統一域名

統一內部連結使用目前鏡像站點。

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

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

(async function ()
{
    const WHITELISTED_HOSTNAMES = ["www.esjzone.cc", "www.esjzone.one", "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).`);
})();