Created
October 20, 2018 22:26
-
-
Save ericek111/f0c7009b551a288671566ccc9692f8b0 to your computer and use it in GitHub Desktop.
HLstatsX activity (sessions) total connection time calculator
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
javascript: (function(e, s) { | |
e.src = s; | |
e.onload = function() { | |
jQuery.noConflict(); | |
$ = jQuery; | |
doStuff(); | |
}; | |
document.head.appendChild(e); | |
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js') | |
function doStuff() { | |
// if playerids is empty AND you're on someone's session page, then calculate from that | |
var playerids = [8590]; | |
var hlstatslink = "http://hlstats.fakaheda.eu/hlxce_186497/hlstats.php?mode=playersessions&player="; | |
sessLenRegexp = /^([\d])[d]\s(\d+)\:(\d+)\:(\d+)[h]$/; | |
var today = new Date(); | |
var maxdate = new Date(); | |
var pdc = function(num) { return num < 10 ? "0" + num : num; } | |
maxdate.setDate(today.getDate() - 2); | |
var countPlayer = function(page, playerid) { | |
var playerName = page.find("div.content > div.block > div:nth-child(9) > div:nth-child(2) > a").first().text().slice(0,-"'s Statistics".length); | |
var totalSess = 0; | |
page.find("table > tbody > tr").each(function(rowi) { | |
if($(this).hasClass("data-table-head")) return; | |
var sessDateStr = new Date($(this).find("td").first().text()); | |
var sessDate = new Date(sessDateStr); | |
if (sessDate > maxdate || sessDate < new Date(today.getFullYear(), today.getMonth(), 1)) | |
return; | |
var sessLenTxt = $(this).find("td").eq(3).html().replace(/ /g,' '); | |
var sessLenMatches = sessLenRegexp.exec(sessLenTxt); | |
totalSess += parseInt(sessLenMatches[1])*24*60*60; | |
totalSess += parseInt(sessLenMatches[2])*60*60; | |
totalSess += parseInt(sessLenMatches[3])*60; | |
totalSess += parseInt(sessLenMatches[4]); | |
}); | |
var sessLenStr = pdc(Math.floor(totalSess/60/60)) + ":" + pdc(Math.floor(totalSess % 3600 / 60)) + ":" + pdc(totalSess % 3600 % 60); | |
console.log("Aktivita " + playerid + " (" + playerName + "): " + totalSess + "s" + " = " + sessLenStr); | |
}; | |
if (playerids.length == 0) { | |
var lasteq = window.location.href.lastIndexOf("player=") + 6 + 1; | |
if (lasteq < window.location.origin.length) | |
return; | |
var pid = parseInt(window.location.href.substring(lasteq)); | |
if (pid <= 0) | |
return; | |
countPlayer($("html").first(), pid); | |
} else { | |
playerids.forEach(function(playerid) { | |
$.get(hlstatslink + playerid, function(data) { countPlayer($("<html/>").html(data), playerid) }); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment