-
-
Save k3n/fb99cb43432be01044f8 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 = $('.flairselectbtn'); | |
var config = { attributes: true, childList: true, characterData: true, subtree: true }; | |
function wait(index){ | |
var $flair = $flairs.eq(index), | |
$post = $flair.closest('.thing'), | |
$popup = $post.find('.flairselector.drop-choices.active'); | |
if ($popup.children().length != 3){ | |
setTimeout(wait, 100, index); | |
console.log("Waiting for " + index); | |
} else { | |
$("#71edc326-33fb-11e5-9620-0ec07e44b9c3").click(); | |
var flairtext = $post.find('.linkflairlabel:first').attr('title'); | |
var $textbox = $popup.find('.customizer.texteditable input[name="text"]'); | |
var $submitbutton = $popup.find('button'); | |
index++; | |
var waitForChange = false; // Mark this as true if you need the script to wait for the submission process. | |
// This is used because when submission 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 submission button. | |
if (flairtext.indexOf("$") == 0) { | |
$("#71edc326-33fb-11e5-9620-0ec07e44b9c3").click(); | |
$textbox.val(flairtext); | |
$submitbutton.click(); | |
waitForChange = true; | |
} else if (flairtext === "Free") { | |
$("#77f4cad0-33fb-11e5-bfe5-0ef6ca535a4d").click(); | |
$textbox.val("Free"); | |
$submitbutton.click(); | |
waitForChange = true; | |
} else if (flairtext === "Code") { | |
$("#764e2d0c-33fb-11e5-a1ad-0e184320b869").click(); | |
$textbox.val("Code"); | |
$submitbutton.click(); | |
waitForChange = true; | |
} | |
if (index >= $flairs.length) { | |
return; | |
} | |
if (waitForChange) { | |
var observer = new MutationObserver(function(mutations) { | |
$flair.click(); | |
wait(index); | |
}); | |
observer.observe($popup[0], config); | |
waitForChange = false; | |
} else { | |
$flair.click(); | |
wait(index); | |
} | |
} | |
} | |
$flairs.eq(0).click(); | |
wait(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment