NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Voat - flair fix
// @namespace https://voat.co/
// @version 0.4
// @description Fixes the 10 link flairs limit for posts
// @author kashka (https://voat.co/u/kashka)
// @include https://voat.co/v/*/comments/*
// @include https://www.voat.co/v/*/comments/*
// @grant none
// @run-at document-start
// @downloadURL https://openuserjs.org/install/kashka/Voat_-_flair_fix.user.js
// ==/UserScript==
(function() {
'use strict';
window.addEventListener("load", function() {
var hasFlair = false, buttons = $(".submission .togglebutton");
for(var i = 0; i < buttons.length; i++) {
if($(buttons[i]).text().trim() == "flair") {
hasFlair = true;
}
}
if(!hasFlair) return;
var postID = location.href.match(/.*\/(\d+)/)[1];
var subName = location.href.match(/\/v\/([^/]+)/)[1];
$.get("/ajaxhelpers/linkflairselectdialog/"+subName+"/"+postID,null,function(n) {
$.ajax({
url:"/v/"+subName+"/about/flair",
dataType:"html",
success:function(x) {
var i;
var flairs = $(x).find(".form-horizontal tr:has(td)");
var flairData = [];
for(i = 0; i < flairs.length; i++) {
var items = $(flairs[i]).find("td");
var data = {
"text": $(items[0]).text(),
"className": $(items[1]).text(),
"id": $(items[2]).find("a").attr("href").match(/.*\/(\d+)$/)[1]
};
flairData.push(data);
}
if(flairData.length > 10) {
var selectflair = function() {
var modal = $("#linkFlairSelectModal");
modal.html(n);
for(i = 10; i < flairData.length; i++) {
var f = flairData[i];
modal.find('[onclick^="return applyflair"]:last').after(
$('<button type="button" class="btn btn-default btn-xs" onclick="return applyflair('+postID+', '+f.id+', \''+f.text+'\', \''+f.className+'\')">'+f.text+'</button>')
);
}
modal.modal();
};
var btnSelect = $('[onclick^="return selectflair"]');
btnSelect.attr("onclick", "");
btnSelect.click(selectflair);
}
}
});
});
}, false);
})();