Efficiency Stat Script

Shows efficiency (attack per piece + downstack per piece)

נכון ליום 04-04-2020. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Efficiency Stat Script
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Shows efficiency (attack per piece + downstack per piece)
// @author       Oki
// @match        https://*.jstris.jezevec10.com/*
// @grant        none
// ==/UserScript==

/**************************
   Efficiency Stat Script
**************************/


(function() {
    window.addEventListener('load', function(){

var STAT_POS = 970;
var STAT_NAME = "Eff"
var enable_playing = true
var enable_replay = true


var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}

var x = true

function afterPlaceBlock() {
    if(this.clock == 0 && x){
      cat = this["v"]["kppElement"].id.slice(-1)
      pieces = this['placedBlocks']
      APP = this["gamedata"]["attack"] / pieces
      DPP = this["gamedata"]["lines"] / pieces
      GameCore[STAT_NAME + "Timestamps"+cat] = GameCore[STAT_NAME + "Timestamps"+cat] || []
      GameCore[STAT_NAME + "Timestamps"+cat].push([(APP + DPP).toFixed(2), this['actions'][this['ptr']]["t"]])
    } else {
      x = false
    }
}

function afterCheckLineClears() {
    pieces = this["GameStats"]["stats"]["BLOCKS"].value
    APP = this["gamedata"]["attack"] / pieces
    DPP = this["gamedata"]["lines"] / pieces
    if(this['GameStats'].get('EFF'))this['GameStats'].get('EFF').set((APP + DPP).toFixed(2));
}



if(enable_playing){
  if(typeof Game != "undefined"){

    var checkLineClearsFunc = GameCore['prototype']['checkLineClears'].toString()
    var params = getParams(checkLineClearsFunc)
    checkLineClearsFunc = trim(checkLineClearsFunc) + trim(afterCheckLineClears.toString())
    GameCore['prototype']['checkLineClears'] = new Function(...params, checkLineClearsFunc);

    var readyGoFunc = Game['prototype']["startReadyGo"].toString()
    readyGoFunc = "EFFStat=0;this['GameStats'].addStat(new StatLine('EFF', '"+STAT_NAME+"', "+STAT_POS+"),true);" + trim(readyGoFunc)
    Game['prototype']["startReadyGo"] = new Function(readyGoFunc);

  }
}


if(enable_replay){

  var website = "jstris.jezevec10.com"
  var url = window.location.href
  var parts = url.split("/")

  if(typeof Replayer != "undefined"){
      Replayer["addStat"] = function(id,into) {
          var newStat = document.createElement("tr");
          newStat.innerHTML = '<td class="ter">'+STAT_NAME+'</td><td class="sval"><span id="'+id+'">0</span></td>'
          into.appendChild(newStat);
      }
  }

  if(parts[3]=="replay" && parts[2].endsWith(website) && parts.length>4){


      var placeBlockFunc = GameCore['prototype']['placeBlock'].toString()
      var params2 = getParams(placeBlockFunc)
      placeBlockFunc =  trim(placeBlockFunc) + trim(afterPlaceBlock.toString())
      GameCore['prototype']['placeBlock'] = new Function(...params2, placeBlockFunc);

      if(parts[4]=="1v1"){
          Replayer["addStat"](STAT_NAME+"Element1",document.getElementsByTagName("tbody")[0])
          Replayer["addStat"](STAT_NAME+"Element2",document.getElementsByTagName("tbody")[2])

      } else {
          Replayer["addStat"](STAT_NAME+"ElementP",document.getElementsByClassName("moreStats")[0])
      }

     Replayer['prototype']['getStat'] = function(cat) {
      if(stamps=GameCore[STAT_NAME+"Timestamps"+cat]){
        for (var i = 1; i < stamps.length; i++) {
          if(stamps[i][1]>this['clock']){
            return stamps[i-1][0]
          }
        }
        return stamps[stamps.length-1][0]
      }
      return 0
     };

     var oldTextBar = View.prototype.updateTextBar.toString();
     oldTextBar = trim(oldTextBar) + ';var cat = this.kppElement.id.slice(-1);eval("'+STAT_NAME+'Element"+cat+"&&('+STAT_NAME+'Element"+cat+".innerHTML = this.g.getStat(cat))");'
     View.prototype.updateTextBar = new Function(oldTextBar);

  }
}

    });
})();