Last active
December 14, 2015 01:59
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); | |
})(); |
chromeの人は拡張使った方が更新とか自動でしてくれるので多分楽。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
の右端の <> を押して一旦ローカルに保存(警告が出てそのままじゃインストール出来なくて、ローカルに保存されてる)
拡張一覧開いてそこにDrag&Drop
参考 http://moondoldo.com/DoldoWorkz/?UserScript%2FChrome%E3%81%A7%E6%89%B1%E3%81%86%E6%96%B9%E6%B3%95#o262938b
後はそれ以降は dotabuff の matchesが有るページに情報追加(matchesやoverviewの所とか)

画面に表示されてるmatchesから計算するので、直近20回のKDAとか、ヒーロー毎のKDAとか出せるよ