Keyboard Display Script

shows keyboard inputs on screen

  1. // ==UserScript==
  2. // @name Keyboard Display Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2201
  5. // @description shows keyboard inputs on screen
  6. // @author Oki
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /**************************
  12. Keyboard Display Script
  13. **************************/
  14.  
  15. (function() {
  16. window.addEventListener('load', function(){
  17.  
  18. shiftRight = 0;
  19.  
  20.  
  21. if(typeof Game != "undefined" || typeof Replayer != "undefined"){
  22.  
  23. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  24. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  25.  
  26.  
  27. var kbhold=document.createElement("div");
  28. kbhold.id="keyboardHolder";
  29. kbhold.style.position="absolute"
  30. kbhold.style.left = (myCanvas.getBoundingClientRect().left - 300) + "px";
  31. kbhold.style.top = (myCanvas.getBoundingClientRect().top + 100) + "px";
  32.  
  33.  
  34. if(typeof Replayer != "undefined" && typeof Game == "undefined") {
  35. Replayer["pressKey"] = function(num,type){
  36. //type: 0=release 1=down 2=press
  37. document.getElementsByClassName("kbkey")[num].style.backgroundColor = type?"lightgoldenrodyellow":""
  38. if(type==2){
  39. setTimeout(x=>{document.getElementsByClassName("kbkey")[num].style.backgroundColor = ""},20)
  40. }
  41.  
  42. }
  43. kbhold.style.left = (myCanvas.getBoundingClientRect().right + 200) + "px";
  44. kbhold.style.top = (myCanvas.getBoundingClientRect().top + 200) + "px";
  45. }
  46.  
  47. document.body.appendChild(kbhold);
  48.  
  49. var f='<R>M{text-align:center;position: absolute;font-size:15px`{]-Q:QIspacing:0;Nred`td|th|Uwp8o_000000;]:inherit`UT_34ff34`Ujy2k_f8a102`UO_f8ff00;}</RYbo"Yps"KPJV"Ptr^Tq180~TqSD~TqHDZ[CCWZXtr^OqHL~OqCWZ[&lt;[v[&gt;X/JK>~</td^|{padding:10px 5pxIR:solidIwidth:2px`q kbkey">`;}M.tg _{]-N#^PtdV-]border[~jy2kqZ~wp8o">YPdiv id="kX</tdP/trPV class="tgU.tg-Ttc3eRstyleQcollapseP><Op39mNcolor:M#kbo KP/divJtableI;]-';var g=0;var i=0;for(i in g='IJKMNOPQRTUVXYZ[]^_`q|~')var e=f.split(g[i]),f=e.join(e.pop())
  50. keyboardHolder.innerHTML = f
  51.  
  52. if(typeof Game == "undefined"){
  53. keyboardHolder.style.left = (parseFloat(keyboardHolder.style.left) + shiftRight) + "px"
  54. }
  55.  
  56.  
  57. if(typeof Game != "undefined") {
  58.  
  59. document['addEventListener']('keydown', press);
  60. document['addEventListener']('keyup', press);
  61. function press(e) {
  62. if(~Game['set2ings'].indexOf(e.keyCode)){
  63. var corresponding = [6,8,1,2,3,5,4,0][Game['set2ings'].indexOf(e.keyCode)]
  64. document.getElementsByClassName("kbkey")[corresponding].style.backgroundColor = ["lightgoldenrodyellow",""][+(e.type=="keyup")]
  65. }
  66. }
  67.  
  68.  
  69. var set2ings = Game['prototype']['readyGo'].toString()
  70. set2ings = "Game['set2ings']=this.Settings.controls;" + trim(set2ings)
  71. Game['prototype']['readyGo'] = new Function(set2ings);
  72.  
  73. var updateTextBarFunc = Game['prototype']['updateTextBar'].toString()
  74. updateTextBarFunc = trim(updateTextBarFunc) + ";kps.innerHTML='KPS: '+(this.getKPP()*this.placedBlocks/this.clock).toFixed(2)"
  75. Game['prototype']['updateTextBar'] = new Function(updateTextBarFunc);
  76. } else {
  77.  
  78.  
  79.  
  80. var website = "jstris.jezevec10.com"
  81. var url = window.location.href
  82. var parts = url.split("/")
  83.  
  84. if(parts[3]=="replay" && parts[2].endsWith(website)){
  85.  
  86. fetch("https://"+parts[2]+"/replay/data?id="+ (parts.length==6?(parts[5]+"&live=1"):(parts[4])))
  87. .then(function(response) {
  88. return response.json();
  89. })
  90. .then(function(jsonResponse) {
  91. var das = jsonResponse.c.das
  92. var playT = Replayer['prototype']['playUntilTime'].toString()
  93. var playTparams = getParams(playT);
  94.  
  95.  
  96. var insert1 = `
  97. kps.innerHTML="KPS: "+(this.getKPP()*this.placedBlocks/(this.clock/1000)).toFixed(2)
  98. this["delayedActions"] = []
  99. for (var i = 0; i < this["actions"].length; i++) {
  100. var action = JSON.parse(JSON.stringify(this["actions"][i]));
  101. if(action.a == 2 || action.a == 3){
  102. action.t = (action.t-`+das+`)>0 ? (action.t-`+das+`) : 0
  103. }
  104. this["delayedActions"].push(action)
  105. }
  106.  
  107. this["delayedActions"].sort(function(a, b) {
  108. return a.t - b.t;
  109. });
  110.  
  111. var oldVals = [this["timer"],this["ptr"]]
  112.  
  113. while (`+playTparams[0]+` >= this['delayedActions'][this['ptr']]['t']) {
  114. if (this['ptr']) {
  115. this['timer'] += (this['delayedActions'][this['ptr']]['t'] - this['delayedActions'][this['ptr'] - 1]['t']) / 1000
  116. };
  117. if(this['delayedActions'][this['ptr']]["a"] == 2){
  118. Replayer["pressKey"](6,1)
  119. }
  120. if(this['delayedActions'][this['ptr']]["a"] == 3){
  121. Replayer["pressKey"](8,1)
  122. }
  123.  
  124. this['ptr']++;
  125. if (this['delayedActions']['length'] === this['ptr']) {
  126. this['reachedEnd'] = true;
  127. break
  128. }
  129. };
  130.  
  131. this["timer"] = oldVals[0]
  132. this["ptr"] = oldVals[1]`
  133.  
  134. var insert2 = `
  135. var highlight = [[6,2],[8,2],[6,0],[8,0],[3,2],[5,2],[0,2],[2,2],[1,2],,[4,2]][this['actions'][this['ptr']]["a"]]
  136. if(highlight){
  137. Replayer["pressKey"](...highlight)
  138. };
  139. `
  140.  
  141. playT = playT.replace(";",insert1+";")
  142. playT = playT.replace("1000};","1000};"+insert2)
  143. Replayer['prototype']['playUntilTime'] = new Function(...playTparams, trim(playT));
  144.  
  145.  
  146.  
  147. });
  148. }
  149.  
  150.  
  151. }
  152.  
  153. }
  154.  
  155.  
  156. });
  157. })();