Skip to content

Instantly share code, notes, and snippets.

@andrask
Last active April 9, 2018 07:58
Show Gist options
  • Save andrask/df8a7ca950670fa9f14aa027b7096565 to your computer and use it in GitHub Desktop.
Save andrask/df8a7ca950670fa9f14aa027b7096565 to your computer and use it in GitHub Desktop.
Are you fed up with trolls on FB? This script adds a "Find trolls" button right next to the "Home" link in the blue bar. Update the trolls list to include all trolls you know. Push the "Find trolls" to mark the comments from these users with a troll face.
// ==UserScript==
// @name Facebook troll finder
// @namespace tag:andrask@github.com,2018:andrask
// @description Find trolls in FB comment authors
// @include http://www.facebook.com/*
// @include https://www.facebook.com/*
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
// License: MIT
// Usage: load it in tampermonkey
// Disclaimer: I'm not a JS developer just really hate trolls and want to mark them.
var trolls = new Set([
"fbname1",
"fbname2",
]);
function findTrolls() {
var trollVersion = 1;
console.log("Finding trolls");
var profiles = document.querySelectorAll('a.UFICommentActorName');
var i;
for (i = 0; i < profiles.length; i++) {
console.log("Finding trolls");
var profile = profiles[i];
if (profile.getAttribute('trollVer') == trollVersion) continue;
var profileUrl = new URL(profile);
var id = profileUrl.searchParams.get('id');
if (!id) {
id = profileUrl.pathname.substring(1);
}
console.log(id);
if (trolls.has(id)) {
profile.insertAdjacentHTML("afterend", "&nbsp;<img width='16px' height='16px' src='https://files.gamebanana.com/img/ico/sprays/spray_trollface_copy.png'></img>");
profile.style = "text-decoration: underline line-through overline;";
}
profile.setAttribute('trollVer', trollVersion);
}
return;
}
window.onload = function() {
var findTrollButton = '<div class="_4kny _2s24"><div class="_3qcu _cy7" data-click="home_icon" id="u_0_n"><a id="_dsfjshfeuudsh" data-gt="{&quot;chrome_nav_item&quot;:&quot;home_chrome&quot;}" href="#" class="_2s25" accesskey="9">Find trolls</a></div></div>';
var homeLink = document.querySelectorAll('div._4kny')[3];
homeLink.insertAdjacentHTML("afterend", findTrollButton);
document.getElementById("_dsfjshfeuudsh").addEventListener('click', findTrolls, false);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment