Created
October 17, 2015 18:10
-
-
Save dannycjones/dad294325eeea70d72d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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