Created
August 22, 2016 07:11
-
-
Save Adidea/5972baa265b9ae01981a777b62dea293 to your computer and use it in GitHub Desktop.
Furaffinity stat tracker
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 Furaffinity stat tracker | |
// @namespace Artex | |
// @include http://www.furaffinity.net/browse?stats=true | |
// @require http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
var Interval = 10000; | |
var Running = true; | |
var StatChart = null; | |
var Site = { | |
getOnlineStats : function(page) { | |
var onlineStats = page.getElementsByClassName("online-stats")[0]; | |
var statTitles = onlineStats.getElementsByTagName("b"); | |
var stats = { | |
users_online : 0, | |
guests : 0, | |
registered : 0, | |
} | |
for (i = 0; i < statTitles.length; i ++) { | |
var title = statTitles[i].textContent; | |
var stat = +statTitles[i].previousSibling.textContent.match(/\d+/) | |
console.log(title, stat); | |
switch(title) { | |
case "Users online": | |
stats.users_online = stat; | |
break; | |
case "guests": | |
stats.guests = stat; | |
break; | |
case "registered": | |
stats.registered = stat; | |
break; | |
} | |
} | |
return stats; | |
}, | |
stats : { | |
traffic : { | |
users_online : [], | |
guests : [], | |
registered : [], | |
}, | |
SPM : [], //submissions per minute | |
timeStamps: [], | |
} | |
} | |
function fetchPage(url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.addEventListener("loadend", function() { | |
callback(this.responseXML); | |
}); | |
//log("GET:", submissions[num], num); | |
xhr.open("GET", url); | |
xhr.responseType = "document"; | |
xhr.send(); | |
} | |
var Submissions = { | |
last : "", | |
log : function(page) { | |
var thumbnails = page.getElementsByClassName("t-image"); | |
if (this.last) { | |
for (i = 0; i < thumbnails.length; i++) { | |
if (thumbnails[i].getAttribute("id") == this.last) { | |
Site.stats.SPM.push(i); | |
console.log("Submissions since last update: "+ i); | |
} | |
} | |
} | |
this.last = thumbnails[0].getAttribute("id"); | |
} | |
} | |
function tracking() { | |
setTimeout(function() { | |
fetchPage("http://www.furaffinity.net/browse/", function(page) { | |
var stats = Site.getOnlineStats(page); | |
Site.stats.traffic.users_online.push(stats.users_online); | |
Site.stats.traffic.guests.push(stats.guests); | |
Site.stats.traffic.registered.push(stats.registered); | |
var date = new Date(); | |
Site.stats.timeStamp = date.getTime(); | |
Site.stats.timeStamps.push(stats); | |
Submissions.log(page); | |
Stat.addData(stats.registered, "Registered users"); | |
StatChart.update(); | |
tracking(); | |
}); | |
}, Interval); | |
} | |
function start() { | |
//clear page | |
//create chart | |
var content = document.getElementsByClassName("page-browse")[0]; | |
content.innerHTML = ""; | |
var canvas = document.createElement("canvas"); | |
canvas.height = "500"; | |
canvas.width = "800" | |
content.appendChild(canvas); | |
var data = { | |
labels: [], | |
datasets:[ | |
{ | |
label : "Registered users", | |
fillColor: "rgba(151,187,205,0.2)", | |
strokeColor: "rgba(151,187,205,1)", | |
pointColor: "rgba(151,187,205,1)", | |
pointStrokeColor: "#fff", | |
pointHighlightFill: "#fff", | |
pointHighlightStroke: "rgba(151,187,205,1)", | |
data: Site.stats.traffic.registered | |
} | |
] | |
} | |
console.log("Chart: " + Chart); | |
var ctx = canvas.getContext("2d"); | |
StatChart = new Chart(ctx).Line(data); | |
tracking(); | |
} | |
start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment