Automatic Replay Code

shows replay code on reset in practice mode

  1. // ==UserScript==
  2. // @name Automatic Replay Code
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.2
  5. // @description shows replay code on reset in practice mode
  6. // @author oki, meppydc
  7. // @match https://*jstris.jezevec10.com/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14. //if (Game['prototype']['pmode'] == 2) {
  15. if (typeof trim != "function") { var trim = a => { a = a.slice(0, -1); a = a.substr(a.indexOf("{") + 1); return a } }
  16. if (typeof getParams != "function") { var getParams = a => { var params = a.slice(a.indexOf("(") + 1); params = params.substr(0, params.indexOf(")")).split(","); return params } }
  17.  
  18. window.copyReplayText = function (number) {
  19. var copyText = document.getElementById("replay" + number);
  20. copyText.select();
  21. document.execCommand("copy");
  22. document.getElementById("replayButton" + number).innerHTML = "Copied!"
  23. setTimeout(() => {
  24. document.getElementById("replayButton" + number).innerHTML = "Copy"
  25. }, 1000);
  26.  
  27. }
  28.  
  29. // var replayCounter = Game['prototype'].toString()
  30. // replayCounter = "this['replayCounter']=1;" + trim(replayCounter)
  31. // Game['prototype'] = new Function(replayCounter);
  32.  
  33.  
  34. function beforeFunction() {
  35. //how many pieces should the replay at least have
  36. let piecesPlacedCutoff = 1
  37.  
  38. if (typeof this['replayCounter'] == "undefined") {
  39. this['replayCounter'] = 1
  40. }
  41.  
  42. this['Replay']['getData']();
  43. //console.log(this["Replay"].string)
  44. //console.log(this.GameStats.stats)
  45.  
  46. if (!this['starting'] && this.GameStats.stats.BLOCKS.value > piecesPlacedCutoff && this['pmode'] == 2) {
  47. //console.log(this["replayCounter"])
  48.  
  49. let replayHTML = "<div style='font-size:14px;'>Userscript Generated Replay <b>#" + this["replayCounter"] + "</b> </div>";
  50. 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>'
  51. replayHTML += '<textarea id=replay' + this["replayCounter"] + ' readonly style="width:75%;" onclick="this.focus();this.select()">' + this['Replay']['string'] + '</textarea>';
  52. replayHTML += '<button id=replayButton' + this["replayCounter"] + ' onclick=window.copyReplayText(' + this["replayCounter"] + ')>Copy</button>'
  53. this["Live"]['chatMajorWarning'](replayHTML);
  54. this["replayCounter"]++;
  55.  
  56. //this['Replay']['uploadError'](this["Live"], 'FROM_USERSCRIPT_UWU');
  57.  
  58. // document.querySelector("#chatInput").value = "/replay"
  59. // document.querySelector("#sendMsg").click()
  60. // document.querySelector("#stage").click()
  61. }
  62. };
  63.  
  64. //add function to readyGo
  65. var readyGoFunc = Game['prototype']['startPractice'].toString()
  66. var params3 = getParams(readyGoFunc)
  67. readyGoFunc = trim(beforeFunction.toString()) + trim(readyGoFunc)
  68. Game['prototype']['startPractice'] = new Function(...params3, readyGoFunc);
  69.  
  70. //}
  71.  
  72. // window.addEventListener('load', function () {
  73. // var resetKey = Game['Settings']['controls'][8]
  74. // console.log("resetKey")
  75. // //console.log(resetKey)
  76. // window.addEventListener('keydown', (e) => {
  77. // if(e.keyCode === 49) {
  78. // document.querySelector("#chatInput").value = "/replay"
  79. // document.querySelector("#sendMsg").click()
  80. // document.querySelector("#stage").click()
  81. // }
  82. // });
  83. // });
  84.  
  85.  
  86. })();