Created
August 7, 2015 04:53
-
-
Save TheLouisHong/842152b11e7b5f6d63a0 to your computer and use it in GitHub Desktop.
ReapplyFlair
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
// By /u/loolo78. Use at you will. | |
// Find the Flair ID by inspecting your flair selection box. | |
// This script unfortunatly is not very "user" friendly. | |
// | |
var flairs = document.getElementsByClassName('flairselectbtn'); | |
var config = { attributes: true, childList: true, characterData: true, subtree: true }; | |
function wait(index){ | |
var temp = flairs[index].parentElement.getElementsByClassName('flairselector drop-choices active')[0]; | |
if (temp == null || temp.children.length != 3){ | |
setTimeout(wait, 100, index); | |
console.log("Waiting for " + index); | |
} else { | |
document.getElementById("71edc326-33fb-11e5-9620-0ec07e44b9c3").click(); | |
var dropdown = flairs[index].parentElement.getElementsByClassName('flairselector drop-choices active')[0]; | |
var flairtext = flairs[index].parentElement.parentElement.parentElement.getElementsByClassName('linkflairlabel')[0].getAttribute('title'); | |
var textbox = dropdown.getElementsByClassName('customizer texteditable')[0].children[0]; | |
var submitbutton = textbox.parentElement.parentElement.getElementsByTagName('button')[0]; | |
index++; | |
var waitForChange = false; // Mark this as true if you need the script to wait for the submittion process. | |
// This is used because when submittion completes it will close every single flair | |
// selection window. So if you have another flair selection open it will close that too. | |
// IMPORTANT: Change the if's below according to your own subreddit. | |
// It will click the type of flair according to the ID. (Example. 71edc326-33fb-11e5-9620-0ec07e44b9c3) | |
// textbox.value is the flair text. | |
// submitbutton is the submittion button. | |
if (flairtext.indexOf("$") == 0) { | |
document.getElementById("71edc326-33fb-11e5-9620-0ec07e44b9c3").click(); | |
textbox.value = flairtext; | |
submitbutton.click(); | |
waitForChange = true; | |
} else if (flairtext === "Free") { | |
document.getElementById("77f4cad0-33fb-11e5-bfe5-0ef6ca535a4d").click(); | |
textbox.value = "Free"; | |
submitbutton.click(); | |
waitForChange = true; | |
} else if (flairtext === "Code") { | |
document.getElementById("764e2d0c-33fb-11e5-a1ad-0e184320b869").click(); | |
textbox.value = "Code"; | |
submitbutton.click(); | |
waitForChange = true; | |
} | |
if (index >= flairs.length) { | |
return; | |
} | |
if (waitForChange) { | |
var observer = new MutationObserver(function(mutations) { | |
flairs[index].click(); | |
wait(index); | |
}); | |
observer.observe(dropdown, config); | |
waitForChange = false; | |
} else { | |
flairs[index].click(); | |
wait(index); | |
} | |
} | |
} | |
flairs[0].click(); | |
wait(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment