Automatic Replay Code

shows replay code on reset in practice mode

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         Automatic Replay Code
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  shows replay code on reset in practice mode
// @author       oki, meppydc
// @match        https://*jstris.jezevec10.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    //if (Game['prototype']['pmode'] == 2) {
        if (typeof trim != "function") { var trim = a => { a = a.slice(0, -1); a = a.substr(a.indexOf("{") + 1); return a } }
        if (typeof getParams != "function") { var getParams = a => { var params = a.slice(a.indexOf("(") + 1); params = params.substr(0, params.indexOf(")")).split(","); return params } }

        window.copyReplayText = function (number) {
            var copyText = document.getElementById("replay" + number);
            copyText.select();
            document.execCommand("copy");
            document.getElementById("replayButton" + number).innerHTML = "Copied!"
            setTimeout(() => {
                document.getElementById("replayButton" + number).innerHTML = "Copy"
            }, 1000);

        }

        // var replayCounter = Game['prototype'].toString()
        //             replayCounter = "this['replayCounter']=1;" + trim(replayCounter)
        //             Game['prototype'] = new Function(replayCounter);


        function beforeFunction() {
            //how many pieces should the replay at least have
            let piecesPlacedCutoff = 1

            if (typeof this['replayCounter'] == "undefined") {
                this['replayCounter'] = 1
            }

            this['Replay']['getData']();
            //console.log(this["Replay"].string)
            //console.log(this.GameStats.stats)

            if (!this['starting'] && this.GameStats.stats.BLOCKS.value > piecesPlacedCutoff && this['pmode'] == 2) {
                //console.log(this["replayCounter"])

                let replayHTML = "<div style='font-size:14px;'>Userscript Generated Replay <b>#" + this["replayCounter"] + "</b> </div>";
                replayHTML += '<div style="font-size:16px;">Time:  <b>' + this.GameStats.stats.CLOCK.value + '</b> Blocks:  <b>' + this.GameStats.stats.BLOCKS.value + '</b> Waste:  <b>' + this.GameStats.stats.WASTE.value + '</b> </div>'
                replayHTML += '<textarea id=replay' + this["replayCounter"] + ' readonly style="width:75%;" onclick="this.focus();this.select()">' + this['Replay']['string'] + '</textarea>';
                replayHTML += '<button id=replayButton' + this["replayCounter"] + ' onclick=window.copyReplayText(' + this["replayCounter"] + ')>Copy</button>'
                this["Live"]['chatMajorWarning'](replayHTML);
                this["replayCounter"]++;

                //this['Replay']['uploadError'](this["Live"], 'FROM_USERSCRIPT_UWU');

                // document.querySelector("#chatInput").value = "/replay"
                // document.querySelector("#sendMsg").click()
                // document.querySelector("#stage").click()
            }
        };

        //add function to readyGo
        var readyGoFunc = Game['prototype']['startPractice'].toString()
        var params3 = getParams(readyGoFunc)
        readyGoFunc = trim(beforeFunction.toString()) + trim(readyGoFunc)
        Game['prototype']['startPractice'] = new Function(...params3, readyGoFunc);

    //}

    // window.addEventListener('load', function () {
    //    var resetKey = Game['Settings']['controls'][8]
    // console.log("resetKey")
    // //console.log(resetKey)
    // window.addEventListener('keydown', (e) => {
    //     if(e.keyCode === 49) {
    //         document.querySelector("#chatInput").value = "/replay"
    // document.querySelector("#sendMsg").click()
    // document.querySelector("#stage").click()
    //     }
    // });
    // });


})();