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

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

目前為 2020-09-29 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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.8
// @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://unpkg.com/ajax-hook@2/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)
    }
})