Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
console.info("specialRep Javascript Loaded.");
var specialRepUsers = [];
var specialRepInterval;
function UserObj(memberID, repMsg, background, prob) {
this.memberID = memberID;
this.repMessage = repMsg;
this.bgColor = background;
this.prob = prob;
return true;
}
function editRep() {
var postElements, usernameElements;
postElements = document.querySelectorAll("div.post_block"); // Selects all posts
if (debug.specialRep) {
console.log("specialRep called");
}
for (var i = 0; i < postElements.length; i++) {
for (var x = 0; x < specialRepUsers.length; x++) {
usernameElements = postElements[i].querySelectorAll("div.post_username span.author a"); // Selects username element within posts.
if (usernameElements[0].href.indexOf(specialRepUsers[x].memberID) != -1) {
if (debug.specialRep) {
console.log("This is Member ID: " + specialRepUsers[x].memberID + "'s rep.");
}
var repElements = postElements[i].querySelectorAll("span.fc.reputation");
if (specialRepUsers[x].actualRep == null) {
specialRepUsers[x].actualRep = repElements[0].innerHTML;
specialRepUsers[x].actualBG = repElements[0].style.backgroundColor;
}
if (Math.random() < specialRepUsers[x].prob) {
repElements[0].innerHTML = specialRepUsers[x].repMessage;
repElements[0].style.backgroundColor = specialRepUsers[x].bgColor
} else {
repElements[0].innerHTML = specialRepUsers[x].actualRep;
repElements[0].style.backgroundColor = "#8db13e"
}
} else {
if (debug.specialRep) {
console.log("This is not Member ID " + specialRepUsers[x].memberID + "'s rep.");
}
}
}
}
return true;
}
function addUser(memberID, repMsg, background, prob) {
var toAdd;
toAdd = new UserObj(memberID, repMsg, background, prob);
specialRepUsers.push(toAdd);
return true;
}
function startSpecialRep() {
if (debug.specialRep) {
console.log("Starting specialRep Interval.");
}
specialRepInterval = setInterval(function () {
editRep()
}, 1000);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.