Last active
December 14, 2015 01:59
-
-
Save withgod/5010882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name dotabuff KDA display | |
// @namespace https://gist.github.com/withgod/5010882/ | |
// @description append KDA info | |
// @author withgod | |
// @include http://dotabuff.com/* | |
// ==/UserScript== | |
(function () { | |
setTimeout(function() { | |
function _get(elem) { | |
return elem.innerText == undefined ? elem.textContent : elem.innerText; | |
} | |
var kill = 0, | |
death = 0, | |
assist = 0, | |
won = 0, | |
lose = 0; | |
var trlist = document.getElementsByTagName('tr'); | |
for (var i = 0;i < trlist.length; i++) { | |
var match = trlist[i]; | |
var tds = match.getElementsByTagName('td'); | |
if (tds.length == 6 || tds.length == 7) { | |
var tabs = match.getElementsByTagName('td'); | |
if (tabs[2].getElementsByTagName('a')[0].className == "won") { | |
won++; | |
} else { | |
lose++; | |
} | |
var kda = _get(tabs[5].getElementsByTagName('div')[0]).replace(/\s+/, "").split("/"); | |
if (kda.length != 3) { | |
kda = _get(tabs[5]).replace(/\s+/, "").split("/"); | |
} | |
kill += parseInt(kda[0]); | |
death += parseInt(kda[1]); | |
assist += parseInt(kda[2]); | |
} | |
} | |
var kd = Math.round(kill / death * 100) / 100; | |
var ad = Math.round(assist / death * 100) / 100; | |
var kda = Math.round((kd + ad) * 100) / 100; | |
var txt = "kd: " + kd + ", "; | |
txt += "ad: " + ad + ", "; | |
txt += "kda: " + kda + ", "; | |
txt += "win rate:" + Math.round(won / (won + lose) * 100) + "%"; | |
var target = document.getElementById('content-header-primary'); | |
var append = document.createElement("div"); | |
append.id = 'append-kda'; | |
append.innerHTML = txt; | |
target.appendChild(append); | |
var header = document.getElementById('content-header'); | |
header.style.height = '80px'; | |
}, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chromeの人は拡張使った方が更新とか自動でしてくれるので多分楽。