-
-
Save ericwoolard/0bc20d5a5b7fb6385c25cd24bc527c07 to your computer and use it in GitHub Desktop.
This file contains 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
// Necessary to perform any API actions | |
var modhash = $("form.logout input[name=uh]").val(); | |
function editFlair(thing, flair, text) { | |
$.post('/api/flair', { | |
api_type: 'json', | |
css_class: flair, | |
link: thing, | |
text: text, | |
uh: modhash | |
}).done(function() { | |
var fullID = "#thing" + thing; | |
$(fullID).addClass('linkflair'); | |
}); | |
} | |
function addQuickFlair() { | |
// Add our special button to all flatlists under threads | |
$('.link .flat-list.buttons').each(function (i, e) { | |
// Skip elements we've already added the dropdown to | |
if ($(e).has('.rgo-qf-dropdown').length) { return; } | |
// Create selected option/trigger div | |
var quickFlair = document.createElement('DIV'); | |
quickFlair.className = 'dropdown lightdrop rgo-qf-dropdown'; | |
var qfDrop = document.createElement('SPAN'); | |
qfDrop.className = "selected"; | |
$(qfDrop).text("quick flair"); | |
quickFlair.appendChild(qfDrop); | |
// Create flair selections div | |
var flairChoices = document.createElement('DIV'); | |
flairChoices.className = 'drop-choices'; | |
var linkFlairs = { | |
'AMA': 'AMA', | |
'Discussion': 'Discussion', | |
'Discussion | eSports': 'Discussion | eSports', | |
'Feedback': 'Feedback', | |
'Fluff': 'Fluff', | |
'Fluff | eSports': 'Fluff | eSports', | |
'Gameplay': 'Gameplay', | |
'Gameplay | eSports': 'Gameplay | eSports', | |
'Gameplay Highlight': 'Stream Highlight', | |
'Guides': 'Tips & Guides', | |
'Help': 'Help', | |
'News': 'News & Events', | |
'News | eSports': 'News & Events | eSports', | |
'Sticky': 'Scheduled Sticky', | |
'UGC': 'User Generated Content', | |
'Update': 'Game Update' | |
}; | |
for (var lf in linkFlairs) { | |
var linkFlair = document.createElement('A'); | |
$(linkFlair).text(lf); | |
linkFlair.title = linkFlairs[lf]; | |
linkFlair.className = 'choice'; | |
$(linkFlair).click(function (ev) { | |
ev.preventDefault(); | |
var flairText = ev.target.innerHTML; | |
var flairClicked = ev.target.innerHTML.replace(' |', '').toLowerCase(); | |
var id = $(ev.target).closest('.thing').attr('data-fullname'); | |
editFlair(id, flairClicked, flairText); | |
var dd = $(ev.target.parentNode).siblings('.rgo-qf-dropdown'); | |
dd.html("flaired!"); | |
dd.removeClass('rgo-qf-dropdown'); | |
}); | |
flairChoices.appendChild(linkFlair); | |
} | |
var li = document.createElement('LI'); | |
var spacer = document.createElement('DIV'); | |
spacer.className = "spacer"; | |
spacer.appendChild(quickFlair); | |
spacer.appendChild(flairChoices); | |
li.appendChild(spacer); | |
e.appendChild(li); | |
}); | |
} | |
// Hook our functions | |
$(window).on('neverEndingLoad', function () { | |
addQuickFlair(); | |
}); | |
$(document).ready(function () { | |
addQuickFlair(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment