I am a big soccer fan, and I love my MLS. I frequent the site and read up on all the articles. Unfortunately, there are a few faces that are always trolling in the comments. I really don’t even care to read what they have to say, as it doesn’t contribute to the discussion. I decided I’d do something about it.
Trolliminator!
Introducing the Trolliminator! bookmarklet.
javascript: (function () {
var trolls = [
'troll', // <-- add troll names here
];
var el = document.createElement('div'),
b = document.getElementsByTagName('body')[0];
otherlib = false, msg = '';
el.style.position = 'fixed';
el.style.height = '32px';
el.style.width = '220px';
el.style.marginLeft = '-110px';
el.style.top = '0';
el.style.left = '50%';
el.style.padding = '5px 10px 5px 10px';
el.style.zIndex = 1001;
el.style.fontSize = '12px';
el.style.color = '#222';
el.style.backgroundColor = '#f99';
if (typeof jQuery != 'undefined') {
msg = 'This page already using jQuery v' + jQuery.fn.jquery;
return showMsg();
} else if (typeof $ == 'function') {
otherlib = true;
}
function getScript(url, success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
script.onload = script.onreadystatechange = function () {
if (!done && (!this.readyState || this.readyState == 'loaded'
|| this.readyState == 'complete')) {
done = true;
success();
}
};
head.appendChild(script);
}
getScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js',
function () {
if (typeof jQuery == 'undefined') {
msg = 'Sorry, but jQuery wasn\'t able to load';
} else {
msg = 'This page is now jQuerified with v' + jQuery.fn.jquery;
if (otherlib) {
msg += ' and noConflict(). Use $jq(), not $().';
}
}
return showMsg();
});
function showMsg() {
el.innerHTML = msg;
b.appendChild(el);
window.setTimeout(function () {
if (typeof jQuery == 'undefined') {
b.removeChild(el);
} else {
jQuery(el).fadeOut('slow', function () {
jQuery(this).remove();
});
if (otherlib) {
$jq = jQuery.noConflict();
}
trolliminator();
}
}, 2500);
}
function trolliminator() {
var $ = jQuery;
var matchCounter = 0;
$.each(trolls, function(index, value) {
$('.gig-comments-comment-username').filter(function() {
var match = $(this).text() == value;
if (match) {
var table = $(this).closest('table');
table.hide();
table.parent().append(
$('<div>').css({ 'color':'#666', 'font-style':'italic' })
.html('Trolliminated!'));
matchCounter++;
return match;
}
});
});
$('<div>').css({
'position':'fixed', 'right':'0', 'bottom':'0',
'padding':'5px', 'font-weight':'bold',
'color':'#090', 'z-index':'99999' })
.html(matchCounter + ' trolls eliminated').appendTo('body');
}
})();
To use it:
- Edit the “trolls” using comma-separated, single-quoted names
- Save it as a bookmarklet
- Hit it up prior to reading any article
It removes posts for matching “trolls” and replaces them with a “Trolliminated!” message. It also puts a counter down in the bottom-right corner. I started to develop a Chrome extension, but I ran into a little trouble and, to be honest, I did not want to put much effort into blocking the trolls – that is just another way they are fed.
🙂
MLSSoccer.com uses Gigya, so this should technically work with any other site that uses Gigya comments.