Skip to content

Instantly share code, notes, and snippets.

@cwparsons
Last active January 2, 2016 05:59
Show Gist options
  • Save cwparsons/8261009 to your computer and use it in GitHub Desktop.
Save cwparsons/8261009 to your computer and use it in GitHub Desktop.
Automate user flair template entries for Reddit
/*!
* Automate user flair template entries for Reddit
* Christopher Parsons <cwlparsons@gmail.com>
*/
// Configuration
var timeout = 500,
flairs = [
{ text: '', css: 'Logo1'},
{ text: '', css: 'Logo2'},
{ text: '', css: 'Logo3'}
];
// Add numbers from 0 - 100
// for (var i = 0; i < 101; i++) {
// flairs.push({ text: '', css: i });
// }
// Main function
(function($, timeout, flairs) {
// Repeat setFlair
function setFlair(i) {
// Find last form entry
var entry = $('#tabbedpane-templates form.flair-entry').last();
// Add the flair text
if (flairs[i].text) {
entry.find('input[name="text"]').val(flairs[i].text);
}
// Add the flair CSS class
if (flairs[i].css) {
entry.find('input[name="css_class"]').val(flairs[i].css);
}
// If a flair has either text or CSS, submit the entry
if (flairs[i].css || flairs[i].text) {
entry.submit();
}
// If there are more flairs, continue through the array
if (i < flairs.length - 1) {
// Delay to allow the submission and template to renew
setTimeout(function() {
setFlair(i + 1);
}, timeout);
}
}
// Run the script
setFlair(0);
})(jQuery, timeout, flairs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment