Show APM & Attack in Replays

Show APM and Attack stats in Jstris replays

目前為 2019-07-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Show APM & Attack in Replays
// @namespace    http://tampermonkey.net/
// @version      0.3
// @author       Oki
// @description  Show APM and Attack stats in Jstris replays
// @match        https://*.jstris.jezevec10.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function(){
/**************************
 APM & Attack in Replays Script
**************************/

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

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

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

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

    if(parts[4]=="1v1"){
        document.getElementsByClassName("ter")[1].innerHTML = "Attack"
        document.getElementsByClassName("ter")[6].innerHTML = "Attack"
        Replayer["addStat"]("apmElement1",document.getElementsByTagName("tbody")[0])
        Replayer["addStat"]("apmElement2",document.getElementsByTagName("tbody")[2])

    } else {
        document.getElementsByClassName("ter")[2].innerHTML = "Attack"
        Replayer["addStat"]("apmElementP",document.getElementsByClassName("moreStats")[0])
    }

   Replayer['prototype']['getAPM'] = function() {
       return ((this['gamedata']['linesSent'] / (this['clock'] / 6000))*10).toFixed(2)
   };

   var oldTextBar = View.prototype.updateTextBar.toString();
   oldTextBar = trim(oldTextBar) + ';var cat = this.kppElement.id.slice(-1);eval("apmElement"+cat+"&&(apmElement"+cat+".innerHTML = this.g.getAPM())");'
   oldTextBar = oldTextBar.replace("this.sentElement.innerHTML=this.g.gamedata.lines,","")
   if(Replayer.prototype.checkLineClears.toString().indexOf("distr")<0){
   		oldTextBar+="this.sentElement.innerHTML=this.g.gamedata.linesSent"
   }
   View.prototype.updateTextBar = new Function(oldTextBar);

}


    });
})();