Skip to content

Instantly share code, notes, and snippets.

@talon
Last active March 23, 2016 14:28
Show Gist options
  • Save talon/7576946 to your computer and use it in GitHub Desktop.
Save talon/7576946 to your computer and use it in GitHub Desktop.
for determining my Bio grade.
/* copy this line and paste it into the javascript console on the bio page:
/* DOESN'T WORK YET.
reqListener = function (stuff) {eval(stuff);};var oReq = new XMLHttpRequest(); oReq.onload = reqListener; oReq.open("get", "https://api.github.com/gists/7576946", true); oReq.send();
*/
// Get the data!
var nl = document.querySelectorAll("label");
var raw_data_array = [];
for(var i = nl.length; i--; raw_data_array.unshift(nl[i].innerHTML));
// Mutate the data!
var parsedScores = []
, pointsEarned = []
, pointsAvailable = [];
raw_data_array.forEach(function (set, i, setArray) {
var test = set.search(/\//g) > -1;
if (test) {
parsedScores.push(set);
}
});
// push all earned points into an array and all available points into another array.
parsedScores.forEach(function (score, i, array) {
var points = score.match(/^\d+/)
, availPoints = score.match(/\d+$/);
if (points) {
pointsEarned.push(+points[0]);
}
if (availPoints) {
pointsAvailable.push(+availPoints[0])
}
});
var totalPointsEarned = 0;
pointsEarned.forEach(function (points, i, array) {
totalPointsEarned += points;
});
var totalPointsAvailable = 0;
pointsAvailable.forEach(function (points, i, array) {
totalPointsAvailable += points;
});
res = Math.floor((totalPointsEarned / totalPointsAvailable) * 100);
res += "%"
var tinker = function(addPointsEarned, addPointsAvailable) {
return (totalPointsEarned + addPointsEarned) / (totalPointsAvailable + addPointsAvailable);
}
console.log("Total Points Earned: " + totalPointsEarned);
console.log("Total Points Available: " + totalPointsAvailable);
console.log("Your grade: " + res);
console.log("Use tinker(addPointsEarned, addPointsAvailable) to fuck around with it");
@james-gibson
Copy link

It could be worse...

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