Greasy Fork 支持简体中文。

Keyboard Display Script

shows keyboard inputs on screen

目前為 2019-08-11 提交的版本,檢視 最新版本

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