Greasy Fork is available in English.

BGA Translation TextBox Export

Add a button on the BGA translation page that allows all the text to be translated on the page to be placed in a text block for easy copying.

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name         BGA Translation TextBox Export
// @version      1.0.1
// @namespace    ani20168
// @description  Add a button on the BGA translation page that allows all the text to be translated on the page to be placed in a text block for easy copying.
// @author       ani20168
// @license      MIT
// @match        https://boardgamearena.com/translation*
// @icon         https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://boardgamearena.com&size=64
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    function setup() {
        // 如果按鈕已經存在,則不再重新建立
        if (document.getElementById('textBoxExportButton')) {
            return;
        }

        // 新增一個按鈕並加入邊界間隔
        let exportButton = document.createElement("input");
        exportButton.type = "button";
        exportButton.value = "TextBox Export";
        exportButton.id = "textBoxExportButton";
        exportButton.className = "bgabutton bgabutton_blue";
        exportButton.style.marginLeft = "4px";  // 加入左邊界間隔

        // 在按鈕下方新增一個文字區塊,並置於新的div中
        let outputDiv = document.createElement("div");
        let outputArea = document.createElement("textarea");
        outputArea.style.width = "100%";
        outputArea.style.height = "200px";
        outputArea.readOnly = true;
        outputArea.style.display = "none";  // 初始時先隱藏
        outputDiv.appendChild(outputArea);

        // 定義按鈕的行為
        exportButton.onclick = function () {
            // 如果文字區塊目前是顯示的,則隱藏它
            if (outputArea.style.display === "block") {
                outputArea.style.display = "none";
            } else {
                // 否則顯示文字區塊並填入readonly_textarea中的文字
                let textAreas = document.getElementsByClassName("readonly_textarea");
                let output = '';

                // 取得所有readonly_textarea中的文字
                for (let i = 0; i < textAreas.length; i++) {
                    output += textAreas[i].value + '\n\n';  // 每個文字間插入兩個換行符號
                }

                // 將蒐集到的文字寫入文字區塊並顯示
                outputArea.value = output;
                outputArea.style.display = "block";
            }
        };

        // 將按鈕和文字區塊添加到"重設過濾器"按鈕旁邊
        let resetFilterButton = document.querySelector('#findreset_form > span');
        resetFilterButton.appendChild(exportButton);

        // 在按鈕容器後方插入新的文字區塊容器
        document.getElementById("filters_buttons").appendChild(outputDiv);
    }

    // 使用MutationObserver監聽DOM變更
    let observer = new MutationObserver(setup);
    observer.observe(document, {childList: true, subtree: true});

    // 初始化設置
    setup();
})();