WowDB家宅本地化

为WowDB的家宅中心提供基于游戏内标准译名的简体中文本地化替换

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         WowDB家宅本地化
// @namespace    https://greasyfork.org/zh-CN/users/1502715
// @version      1.7
// @description  为WowDB的家宅中心提供基于游戏内标准译名的简体中文本地化替换
// @author       电视卫士
// @license      MIT
// @match        https://housing.wowdb.com/*
// @exclude      https://housing.wowdb.com/embed/*
// @exclude      https://housing.wowdb.com/changelog/*
// @grant        none
// @require      https://cdn.jsdelivr.net/gh/SGSwdzgr/wowdb-localization@98bd48a9b99f49865c664b16c49efc2699d3a3eb/dict.js
// ==/UserScript==

(function() {
    'use strict';

    function localizeText(node) {
        if (!window.WowDBDict) return;
        if (node.nodeType === 3) {
            let text = node.nodeValue;
            for (const [en, zh] of Object.entries(window.WowDBDict)) {
                text = text.replace(new RegExp("\\b" + en + "\\b", "g"), zh);
            }
            node.nodeValue = text;
        } else {
            node.childNodes.forEach(localizeText);
        }
    }

    function runLocalization() {
        localizeText(document.body);
    }

    const observer = new MutationObserver(() => runLocalization());
    observer.observe(document.body, { childList: true, subtree: true });
    runLocalization();
})();