Greasy Fork

Greasy Fork is available in English.

POE 网页市集道具转英文2

流放之路国服网页市集物品转换为国际服pob物品工具

当前为 2023-10-21 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         POE 网页市集道具转英文2
// @namespace    http://tampermonkey.net/
// @version      0.0.4
// @description  流放之路国服网页市集物品转换为国际服pob物品工具
// @author       Rxdey
// @match        https://poe.game.qq.com/trade/*
// @icon         https://poecdn.game.qq.com/protected/image/tencent/favicon-32x32.png?v=1&key=WDwrBirzWbDsbHkc0BgCMQ
// @require      https://unpkg.com/[email protected]/dist/db.global.js
// @require      https://unpkg.com/[email protected]/dist/creater.global.js
// @require      https://unpkg.com/[email protected]/dist/translator.global.js
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';
    const copyToClipboard = (txt, cb = () => { }) => {
        const node = document.createElement('textarea');
        node.value = txt;
        node.class = 'copy-txt';
        document.body.appendChild(node);
        node.select();
        document.execCommand('Copy');
        document.body.removeChild(node);
        cb();
    };
    const setButton = () => {
        const targets = Array.from(document.querySelectorAll('.row[data-id]'));
        console.log(targets);
        if (!targets || !targets.length) return;

        targets.forEach(target => {
            if (target.querySelector('.copy-en')) return;
            const leftEl = target.querySelector('.left');
            if (!leftEl) return;
            const btn = document.createElement('div');
            btn.className = 'copy-en';
            btn.title = '复制为英文';
            btn.setAttribute('style', `position: absolute;
            left: 84px;
            bottom: 8px;
            color: #fff;
            font-size: 14px;
            cursor: pointer;
            text-decoration: underline;`);
            btn.innerText = '复制为英文';
            leftEl.appendChild(btn);
            btn.addEventListener('click', () => {
                const text = target.__vue__.itemText;
                // 不先放里面翻译不完整
                let textarea = document.createElement('textarea');
                textarea.value = text;
                const factory = CnPoeTranslator.newBasicTranslatorFactory(CnPoeExportDb);
                const textTranslator = factory.getTextTranslator();
                const res = textTranslator.translate(textarea.value);
                textarea = null;
                copyToClipboard(res);
                target.__vue__.itemTextCopied();
            });
        });
    };
    const observer = new MutationObserver((mutationsList, observer) => {
         for (let mutation of mutationsList) {
              if (mutation.target.className !== 'resultset') return;
             setButton();
         }
    });
    console.log('翻译复制初始化');
        const targetNode = document.querySelector('body');
        const config = { childList: true, subtree: true };
        observer.observe(targetNode, config);
})();