Efficiency Stat Script

Shows efficiency (attack per piece + downstack per piece)

As of 2020-04-05. See the latest version.

  1. // ==UserScript==
  2. // @name Efficiency Stat Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.1
  5. // @description Shows efficiency (attack per piece + downstack per piece)
  6. // @author Oki
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /**************************
  12. Efficiency Stat Script
  13. **************************/
  14.  
  15.  
  16. (function() {
  17. window.addEventListener('load', function(){
  18.  
  19. STAT_POS = 970;
  20. STAT_NAME = "Eff"
  21.  
  22. STAT_POS2 = 1000;
  23. STAT_NAME2 = "VS"
  24.  
  25. enable_playing = true
  26. enable_replay = true
  27. enable_vsscore = true
  28.  
  29. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  30. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  31.  
  32. x = true
  33.  
  34. function afterPlaceBlock() {
  35. if(this.clock == 0 && x){
  36. GameCore['downstack'] += (currentGarbage - (JSON.stringify(this.matrix).split(8).length-1)/9)
  37. cat = this["v"]["kppElement"].id.slice(-1)
  38. pieces = this['placedBlocks']
  39. APP = this["gamedata"]["attack"] / pieces
  40. DPP = GameCore['downstack'] / pieces
  41. EFF = (APP + DPP)
  42. time = this['actions'][this['ptr']]["t"]
  43. GameCore[STAT_NAME + "Timestamps"+cat] = GameCore[STAT_NAME + "Timestamps"+cat] || []
  44. GameCore[STAT_NAME + "Timestamps"+cat].push([(EFF).toFixed(2), time])
  45.  
  46. } else {
  47. x = false;
  48. GameCore['downstack'] = 0;
  49. ["1","2","P"].map(y=>{
  50. if(GameCore[STAT_NAME + "Timestamps" + y]){
  51. GameCore[STAT_NAME + "Timestamps" + y].push()
  52. }
  53. })
  54. }
  55.  
  56. }
  57.  
  58. function afterCheckLineClears() {
  59. GameCore['downstack'] += (currentGarbage - (JSON.stringify(this.matrix).split(8).length-1)/9)
  60. pieces = this["GameStats"]["stats"]["BLOCKS"].value
  61. APP = this["gamedata"]["attack"] / pieces
  62. DPP = GameCore['downstack'] / pieces
  63. if(enable_vsscore){
  64. PPS = this['getPPS']()
  65. if(this['GameStats'].get('VS'))this['GameStats'].get('VS').set(((APP + DPP)*PPS).toFixed(2));
  66. }
  67. if(this['GameStats'].get('EFF'))this['GameStats'].get('EFF').set((APP + DPP).toFixed(2));
  68. }
  69.  
  70. function beforeCheckLineClears() {
  71. window.currentGarbage = (JSON.stringify(this.matrix).split(8).length-1)/9;
  72. }
  73.  
  74. if(enable_playing | enable_replay){
  75. var checkLineClearsFunc = GameCore['prototype']['checkLineClears'].toString()
  76. var params = getParams(checkLineClearsFunc)
  77. checkLineClearsFunc = trim(beforeCheckLineClears.toString()) + trim(checkLineClearsFunc)
  78. GameCore['prototype']['checkLineClears'] = new Function(...params, checkLineClearsFunc);
  79. }
  80.  
  81.  
  82.  
  83. if(enable_playing){
  84. if(typeof Game != "undefined"){
  85.  
  86. checkLineClearsFunc = GameCore['prototype']['checkLineClears'].toString()
  87. checkLineClearsFunc = trim(checkLineClearsFunc) + trim(afterCheckLineClears.toString())
  88. GameCore['prototype']['checkLineClears'] = new Function(...params, checkLineClearsFunc);
  89.  
  90. var readyGoFunc = Game['prototype']["startReadyGo"].toString()
  91. readyGoFunc = `
  92. GameCore['downstack']=0;
  93. this['GameStats'].addStat(new StatLine('EFF', '`+STAT_NAME+`', `+STAT_POS+`),true);
  94. this['GameStats'].addStat(new StatLine('VS', '`+STAT_NAME2+`', `+STAT_POS2+`),true);` + trim(readyGoFunc)
  95. Game['prototype']["startReadyGo"] = new Function(readyGoFunc);
  96.  
  97. }
  98. }
  99.  
  100.  
  101. if(enable_replay){
  102.  
  103. var website = "jstris.jezevec10.com"
  104. var url = window.location.href
  105. var parts = url.split("/")
  106.  
  107. if(typeof Replayer != "undefined"){
  108. Replayer["addStat"] = function(id,into,name) {
  109. var newStat = document.createElement("tr");
  110. newStat.innerHTML = '<td class="ter">'+name+'</td><td class="sval"><span id="'+id+'">0</span></td>'
  111. into.appendChild(newStat);
  112. }
  113. }
  114.  
  115. if(parts[3]=="replay" && parts[2].endsWith(website) && parts.length>4){
  116.  
  117. GameCore['downstack'] = 0
  118. var placeBlockFunc = GameCore['prototype']['placeBlock'].toString()
  119. var params2 = getParams(placeBlockFunc)
  120. placeBlockFunc = trim(placeBlockFunc) + trim(afterPlaceBlock.toString())
  121. GameCore['prototype']['placeBlock'] = new Function(...params2, placeBlockFunc);
  122.  
  123. if(parts[4]=="1v1"){
  124. Replayer["addStat"](STAT_NAME+"Element1",document.getElementsByTagName("tbody")[0],STAT_NAME)
  125. Replayer["addStat"](STAT_NAME+"Element2",document.getElementsByTagName("tbody")[2],STAT_NAME)
  126.  
  127. if(enable_vsscore){
  128. Replayer["addStat"](STAT_NAME2+"Element1",document.getElementsByTagName("tbody")[0],STAT_NAME2)
  129. Replayer["addStat"](STAT_NAME2+"Element2",document.getElementsByTagName("tbody")[2],STAT_NAME2)
  130. }
  131. } else {
  132. Replayer["addStat"](STAT_NAME+"ElementP",document.getElementsByClassName("moreStats")[0])
  133. if(enable_vsscore){
  134. Replayer["addStat"](STAT_NAME2+"ElementP",document.getElementsByClassName("moreStats")[0])
  135. }
  136. }
  137.  
  138. Replayer['prototype']['getStat'] = function(cat) {
  139. if(stamps=GameCore[STAT_NAME+"Timestamps"+cat]){
  140. for (var i = 1; i < stamps.length; i++) {
  141. if(stamps[i][1]>this['clock']){
  142. return stamps[i-1][0]
  143. }
  144. }
  145. return stamps[stamps.length-1][0]
  146. }
  147. return 0
  148. };
  149.  
  150. var oldTextBar = View.prototype.updateTextBar.toString();
  151. oldTextBar = trim(oldTextBar) + `;
  152. var cat = this.kppElement.id.slice(-1);
  153. eval("`+STAT_NAME+`Element"+cat+"&&(`+STAT_NAME+`Element"+cat+".innerHTML = this.g.getStat(cat))");
  154. if(enable_vsscore){
  155. eval("`+STAT_NAME2+`Element"+cat+"&&(`+STAT_NAME2+`Element"+cat+".innerHTML = ($('#PPS'+cat)[0].innerHTML*this.g.getStat(cat)).toFixed(2))");
  156. }`
  157. View.prototype.updateTextBar = new Function(oldTextBar);
  158.  
  159. }
  160. }
  161.  
  162. });
  163. })();
  164.