Efficiency Stat Script

Shows efficiency (attack per piece + downstack per piece)

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

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