GW2 Skill Zh-CN 激战2 技能翻译插件 by Saber Lily

把 激战2 Metabattle, Snowrows, discretize 等攻略网站上面的英文技能描述替换成中文,方便美服/欧服玩家参考。

当前为 2021-04-29 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GW2 Skill Zh-CN 激战2 技能翻译插件 by Saber Lily
// @name:en      GW2 Skill Zh-CN GW2ARMORY Translator by Saber Lily
// @namespace    https://greasyfork.org/zh-CN/scripts/377052
// @version      1.9
// @description  把 激战2 Metabattle, Snowrows, discretize 等攻略网站上面的英文技能描述替换成中文,方便美服/欧服玩家参考。
// @description:en    Show Chinese GW2 Skill Translation which are on Metabattle, Snowrows, discretize and so on.
// @icon         https://wiki.guildwars2.com/favicon.ico
// @author       Saber Lily 莉莉哩哩 Gay哩Gay气
// @run-at       document-start
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/ajaxhook.min.js
// @match        https://metabattle.com/wiki/*
// @match        https://snowcrows.com/*
// @match        https://lucky-noobs.com/*
// @match        https://discretize.eu/*
// @match        https://www.godsofpvp.net/*
// @match        https://fast.farming-community.eu/*
// @match        https://guildjen.com/*
// @grant        none
// @license      GPL-v3
// ==/UserScript==

// 作者简介
// Saber Lily.1960 Current in WSR EU Server
// 莉莉哩哩 Gay哩Gay气,一个天天划水的休闲 激战2 欧服玩家。
// 如果你觉得该脚本对你有所帮助,欢迎赞助我!

// 脚本原理
// 1. 通过 GW2A_EMBED_OPTIONS 选项,调整及修改 GW2ARMORY 的请求参数
// 2. 通过劫持 Metabattle, Snowrows, discretize 的 Ajax Api 请求,篡改其访问地址,使其返回中文数据。

// 版权申明
// 本脚本为 Saber Lily.1960 原创,未经作者授权禁止转载,禁止转载范围包括但不仅限于:贴吧、NGA论坛等。

// 已知 Bug,不会修复
// 1. Metabattle 没有食物、扳手等的翻译
// 2. Metabattle 武器组、法印及部分武器技能没有翻译
// 3. 燃火 F1、F2 及 F3 后的技能没有翻译

console.log('GW2 Skill Zh-CN 激战2技能翻译插件 by Saber Lily 已启用!')

document.GW2A_EMBED_OPTIONS = {
    lang: 'zh'
};

window.onload = function() {
    document.body.addEventListener('mousedown', ev => {
        const a = event.target.closest('a');
        if (a && a.hasAttribute('href') && a.getAttribute('href').toString().includes('guildwars2.com/wiki/Special:Search/')) {
            const b = a.parentNode.parentNode.parentNode;
            if (b.hasAttribute('data-armory-ids')) {
                const c = b.getElementsByClassName('gw2a--M9jBV');
                var wikiid = 0;
                if (c.length > 1) {
                    for (let i = 0; i < c.length; i++) {
                        if (c[i].contains(a)) {
                            wikiid = b.getAttribute('data-armory-ids').toString().split(',')[i];
                            break;
                        }
                    }
                } else {
                    wikiid = b.getAttribute('data-armory-ids').toString().replace(',', '');
                }
                a.href = 'https://wiki.guildwars2.com/wiki/Special:RunQuery/Search_by_id?title=Special%3ARunQuery%2FSearch_by_id&pfRunQueryFormName=Search+by+id&Search+by+id%5Bid%5D=' + wikiid;
            };
        }
    });
}

ah.proxy({
    onRequest: (config, handler) => {
        if (config.url.startsWith('https://api.guildwars2.com/')) {
            config.url = config.url.replace('lang=en', 'lang=zh');
            console.log(config, handler);
        }
        handler.next(config);
    },
    onError: (err, handler) => {
        handler.next(err)
    },
    onResponse: (response, handler) => {
        handler.next(response)
    }
})