WowDB家宅本地化

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();
})();