Skip to content

Instantly share code, notes, and snippets.

@withgod
Last active December 14, 2015 01:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save withgod/5010882 to your computer and use it in GitHub Desktop.
Save withgod/5010882 to your computer and use it in GitHub Desktop.
// ==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);
})();
@withgod
Copy link
Author

withgod commented Feb 22, 2013

dl
の右端の <> を押して一旦ローカルに保存(警告が出てそのままじゃインストール出来なくて、ローカルに保存されてる)

拡張一覧開いてそこに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の所とか)
thumb
画面に表示されてるmatchesから計算するので、直近20回のKDAとか、ヒーロー毎のKDAとか出せるよ

@withgod
Copy link
Author

withgod commented Mar 17, 2014

chromeの人は拡張使った方が更新とか自動でしてくれるので多分楽。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment