Keyboard Display Script

shows keyboard inputs on screen

Fra 09.07.2019. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name Keyboard Display Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  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.  
  19. if(typeof Game != "undefined" || typeof Replayer != "undefined"){
  20.  
  21. if(typeof getParams != "function"){var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}}
  22. if(typeof trim != "function"){var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}}
  23.  
  24. document['addEventListener']('keydown', press);
  25. document['addEventListener']('keyup', press);
  26. function press(e) {
  27. if(~Game['set2ings'].indexOf(e.keyCode)){
  28. var corresponding = [6,8,1,2,3,5,4,0][Game['set2ings'].indexOf(e.keyCode)]
  29. document.getElementsByClassName("kbkey")[corresponding].style.backgroundColor = ["lightgoldenrodyellow",""][+(e.type=="keyup")]
  30. }
  31. }
  32. function pressKey(num,type){
  33. //type: 0=release 1=down 2=press
  34. document.getElementsByClassName("kbkey")[num].style.backgroundColor = type?"lightgoldenrodyellow":""
  35. if(type==2){
  36. setTimeout(x=>{document.getElementsByClassName("kbkey")[num].style.backgroundColor = ""},100)
  37. }
  38.  
  39. }
  40.  
  41. var kbhold=document.createElement("div");
  42. kbhold.id="keyboardHolder";
  43. kbhold.style.position="absolute"
  44. kbhold.style.left = (myCanvas.getBoundingClientRect().left - 300) + "px";
  45. kbhold.style.top = (myCanvas.getBoundingClientRect().top + 100) + "px";
  46.  
  47. if(typeof Replayer != "undefined") {
  48. kbhold.style.top = (myCanvas.getBoundingClientRect().top + 200) + "px";
  49. }
  50.  
  51. document.body.appendChild(kbhold);
  52.  
  53. 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())
  54. keyboardHolder.innerHTML = f
  55.  
  56.  
  57. if(typeof Game != "undefined") {
  58. var set2ings = Game['prototype']['readyGo'].toString()
  59. set2ings = "Game['set2ings']=this.Settings.controls;" + trim(set2ings)
  60. Game['prototype']['readyGo'] = new Function(set2ings);
  61.  
  62. var updateTextBarFunc = Game['prototype']['updateTextBar'].toString()
  63. updateTextBarFunc = trim(updateTextBarFunc) + ";kps.innerHTML='KPS: '+(this.getKPP()*this.placedBlocks/this.clock).toFixed(2)"
  64. Game['prototype']['updateTextBar'] = new Function(updateTextBarFunc);
  65. } else {
  66.  
  67.  
  68.  
  69. var website = "jstris.jezevec10.com"
  70. var url = window.location.href
  71. var parts = url.split("/")
  72.  
  73. if(parts[3]=="replay" && parts[2].endsWith(website)){
  74.  
  75. fetch("https://"+parts[2]+"/replay/data?id="+ (parts.length==6?(parts[5]+"&live=1"):(parts[4])))
  76. .then(function(response) {
  77. return response.json();
  78. })
  79. .then(function(jsonResponse) {
  80. var das = jsonResponse.c.das
  81. var playT = Replayer['prototype']['playUntilTime'].toString()
  82. var playTparams = getParams(playT);
  83.  
  84.  
  85. var insert1 = `
  86. if(clock%500==0){kps.innerHTML="KPS: "+(this.getKPP()*this.placedBlocks/(this.clock/1000)).toFixed(2)}
  87. this["delayedActions"] = []
  88. for (var i = 0; i < this["actions"].length; i++) {
  89. var action = JSON.parse(JSON.stringify(this["actions"][i]));
  90. if(action.a == 2 || action.a == 3){
  91. action.t = (action.t-`+das+`)>0 ? (action.t-`+das+`) : 0
  92. }
  93. this["delayedActions"].push(action)
  94. }
  95.  
  96. this["delayedActions"].sort(function(a, b) {
  97. return a.t - b.t;
  98. });
  99.  
  100. var oldVals = [this["timer"],this["ptr"]]
  101.  
  102. while (`+playTparams[0]+` >= this['delayedActions'][this['ptr']]['t']) {
  103. if (this['ptr']) {
  104. this['timer'] += (this['delayedActions'][this['ptr']]['t'] - this['delayedActions'][this['ptr'] - 1]['t']) / 1000
  105. };
  106. if(this['delayedActions'][this['ptr']]["a"] == 2){
  107. pressKey(6,1)
  108. }
  109. if(this['delayedActions'][this['ptr']]["a"] == 3){
  110. pressKey(8,1)
  111. }
  112.  
  113. this['ptr']++;
  114. if (this['delayedActions']['length'] === this['ptr']) {
  115. this['reachedEnd'] = true;
  116. break
  117. }
  118. };
  119.  
  120. this["timer"] = oldVals[0]
  121. this["ptr"] = oldVals[1]`
  122.  
  123. var insert2 = `
  124. 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"]]
  125. if(highlight){
  126. pressKey(...highlight)
  127. };
  128. `
  129.  
  130. playT = playT.replace(";",insert1+";")
  131. playT = playT.replace("1000};","1000};"+insert2)
  132.  
  133. Replayer['prototype']['playUntilTime'] = new Function(...playTparams, trim(playT));
  134.  
  135.  
  136.  
  137. });
  138. }
  139.  
  140.  
  141. }
  142.  
  143. }
  144.  
  145.  
  146. });
  147. })();