Average game times for League of Legends match history display.
function get_game_times() {
var durs = document.querySelectorAll('.date-duration-duration'),
games = Array();
for ( i in durs) {
var dtxt = durs[i].innerText;
if (dtxt != undefined) {
// Does it output hours? i have no appplicable data to test.
var tar = dtxt.match(/(\d\d):(\d\d)/),
tm = Number(tar[1]),
ts = Number(tar[2])/60, // convert seconds to percentage
t = tm + ts;
games.push(t);
}
}
return games;
}
function summery_text (games, totaltime, sep) {
if (sep == undefined){ sep ='\n'; }
var average = totaltime/games.length,
summery = "Total Time : " +totaltime.toString() + sep +
"Number of Games: " + games.length + sep +
"Average Time: " + average.toString() + sep +
"Note time value format is: '<Minutes>.<SecondsAsAPercentage>'";
return summery;
}
function sum (ar) {
var t = 0;
for (var i = 0; i < ar.length; i++) { t += ar[i]; }
return t;
}
var games = get_game_times(),
totaltime = sum(games);
//alert(games);
alert(summery_text(games, totaltime));