Greasy Fork

Translator Portal Ease of Use

Adds a Skip button for undetected invalid translations.

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

// ==UserScript==
// @name         Translator Portal Ease of Use
// @namespace    https://www.roblox.com/games/263761432/Horrific-Housing
// @version      1.3.0
// @description  Adds a Skip button for undetected invalid translations.
// @author       wut
// @match        https://www.roblox.com/localization/games/107172930/translations?languageCode=*
// @icon         https://cdn.discordapp.com/attachments/685584087376986124/859100206297120778/unknown.png
// @grant        none
// ==/UserScript==

// IS THE SITE LOADED?
window.addEventListener("load", function(){

    // EXPAND ALL CONTEXT TABS
    var info1 = document.querySelectorAll('.section-title')[0];
    info1.click();
    var info2 = document.querySelectorAll('.section-title')[1];
    info2.click();
    var info3 = document.querySelectorAll('.section-title')[2];
    info3.click();

    // CREATING THE BUTTON
	var clone = document.querySelector('#selenium-save-entry-button').cloneNode( true );
	clone.setAttribute('id', 'selenium-skip-button');
	document.querySelectorAll('.col-sm-6')[2].appendChild( clone );
	clone.innerHTML = "Skip";
	document.getElementById("selenium-skip-button").style.marginRight = "10px";
	clone.removeAttribute("disabled")

	// DEFINING THE INPUT TEXTBOX
	var inputbox = document.getElementById("selenium-translation-text");

	// INVALID BUTTON LISTENER FUNCTION
	document.getElementById("selenium-skip-button").addEventListener("click", function() {

		// COPYING AND PASTING THE TEXT
		inputbox.value = document.getElementById("selenium-entry-source-text").innerHTML;
		inputbox.innerHTML = document.getElementById("selenium-entry-source-text").innerHTML;
		inputbox.classList.remove("ng-pristine");
		inputbox.classList.remove("ng-empty");
		inputbox.classList.add("ng-valid");
		inputbox.classList.add("ng-not-empty");
		inputbox.classList.add("ng-dirty");
		inputbox.classList.add("ng-valid-parse");

		// MANUAL TEXTBOX UPDATE (IMPORTANT)
		if ("createEvent" in document) {
			var evt = document.createEvent("HTMLEvents");
			evt.initEvent("change", false, true);
			inputbox.dispatchEvent(evt);
		}
		else {
			inputbox.fireEvent("onchange");
		}

		// AUTOMATICALLY CLICK SAVE
		var save = document.querySelector('#selenium-save-entry-button');
		save.click();

	});


    // PLAYERGUI SPECTATE FRAME TITLE AUTOSKIP
    const observer = new MutationObserver(mutation => {
        try {
            if (document.querySelector('[uib-tooltip="PlayerGui.Spectate.Frame.Title"]').innerHTML) {
            document.getElementById("selenium-skip-button").click();
            }
        } catch {
            try {
                if (document.querySelector('[uib-tooltip="PlayerGui.WarpToPlayer.Box.ScrollingFrame.template"]').innerHTML) {
                    document.getElementById("selenium-skip-button").click();
                }
            } catch {
                try {
                    if (document.querySelector('[uib-tooltip="Workspace.Plates.{{player1}}.House.Sign.SurfaceGui.TextLabel"]').innerHTML) {
                        document.getElementById("selenium-skip-button").click();
                    }
                } catch {
                    try {
                        if (document.querySelector('[uib-tooltip="PlayerGui.Assasin.Frame.PlayerName"]').innerHTML) {
                            document.getElementById("selenium-skip-button").click();
                        }
                    } catch {
                        console.log();
                    }
                }
            }
        }
    });

    observer.observe(document.getElementById("selenium-entry-source-text"), {
        childList: true,
        attributes: true,
        subtree: true,
        characterData: true
    });

});