// ==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 // @downloadURL 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).`); })();