Skip to content

Instantly share code, notes, and snippets.

@aldykins
Last active October 12, 2015 03:08
Show Gist options
  • Save aldykins/3962280 to your computer and use it in GitHub Desktop.
Save aldykins/3962280 to your computer and use it in GitHub Desktop.
adds yen per day/week/month and raw upload/download values to your AB profile page
// ==UserScript==
// @name Animebytes raw upload/download
// @description adds raw upload/download values to your AB profile page
// @include *animebytes.tv/user.php?id=*
// @icon http://animebytes.tv/favicon.ico
// ==/UserScript==
function formatInteger(intStr){
intStr += '';
fmtStr = '';
for (i= intStr.length - 1; i >= 0; i--){
if ((i - intStr.length) % 3 == 0)
fmtStr = ' ' + intStr[i] + fmtStr;
else
fmtStr = intStr[i] + fmtStr;
}
return fmtStr
}
function addDefinition(after, definition, value){
dt = document.createElement('dt');
dt.appendChild(document.createTextNode(definition));
dd = document.createElement('dd');
dd.appendChild(document.createTextNode(value));
after.parentNode.insertBefore(dd, after.nextSibling);
after.parentNode.insertBefore(dt, after.nextSibling);
}
function addDefinitionBefore(before, definition, value){
dt = document.createElement('dt');
dt.appendChild(document.createTextNode(definition));
dd = document.createElement('dd');
dd.appendChild(document.createTextNode(value));
before.parentNode.insertBefore(dt, before.previousSibling.previousSibling);
before.parentNode.insertBefore(dd, before.previousSibling.previousSibling);
}
function addRealStats(){
//find commented stats
var hidden = "//li[@style='overflow-x: hidden;']/../comment()"
var hiddenNode = document.evaluate(hidden, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
//get the stats, matches[1] is download amount [2] is MB/GB/TB [3] is per day
var ulMatcher = /.*Uploaded:\s+(\d+\.*\d*)\s+([A-Z]+)\s\((.*)\)\.*/i;
var ulMatches = ulMatcher.exec(hiddenNode.textContent);
var dlMatcher = /.*Downloaded:\s+(\d+\.*\d*)\s+([A-Z]+)\s\((.*)\)\.*/i;
var dlMatches = dlMatcher.exec(hiddenNode.textContent);
//get the user stats bar
var statsPath = "//div[@class='userstatsright']/dl/dd[2]";
var statsNode = document.evaluate(statsPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
//add the definitions to the user stats
addDefinition(statsNode, "Raw Downloaded:", dlMatches[1] + " " + dlMatches[2] + " (" + dlMatches[3] + ") ");
addDefinition(statsNode, "Raw Uploaded:", ulMatches[1] + " " + ulMatches[2] + " (" + ulMatches[3] + ") ");
}
var href = window.location.href;
var urlMatcher = /.*animebytes\.tv\/user.php\?id=\d+$/i;
if (urlMatcher.test(href)){
//do this first or added stats will change its position...
var yphPath = "//div[@class='userstatsright']/dl/dd[10]";
var yphNode = document.evaluate(yphPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
addRealStats();
//addDefinition(yphNode, 'Yen per month:', '~' + formatInteger(yphNode.textContent * 30));
//addDefinition(yphNode, 'Yen per week:', formatInteger(yphNode.textContent * 7));
//addDefinition(yphNode, 'Yen per day:', formatInteger(yphNode.textContent));
addDefinitionBefore(yphNode, 'Yen per hour:', formatInteger(Math.round(yphNode.textContent / 24)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment