Last active
September 30, 2023 12:58
-
-
Save Helios-vmg/b2b845a3eec280571e6f34869504c8cf 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
// ==UserScript== | |
// @name MoronSilencer | |
// @version 1 | |
// @grant none | |
// @match http://www.cplusplus.com/forum/* | |
// ==/UserScript== | |
console.log('MoronSilencer is working its magic'); | |
var morons = [ /*write the name of your morons here*/ ]; | |
function map(xs, f){ | |
var ret = []; | |
for (var i = 0; i < xs.length; i++) | |
ret.push(f(xs[i])); | |
return ret; | |
} | |
function get_post_node(node){ | |
while (node.className != 'C_forPost') | |
node = node.parentNode; | |
return node; | |
} | |
function remove_moronic_posts(){ | |
var whos = document.getElementsByClassName('dwho'); | |
var l = whos.length; | |
var list = map(morons, x => '/user/' + x + '/'); | |
for (var i = 0; i < l;){ | |
var who = whos[i]; | |
if (!who){ | |
i++; | |
continue; | |
} | |
if (!who.firstChild.getAttribute){ | |
i++; | |
continue; | |
} | |
var name = who.firstChild.getAttribute('href'); | |
if (list.indexOf(name) < 0){ | |
i++; | |
continue; | |
} | |
get_post_node(who).remove(); | |
l--; | |
} | |
} | |
function remove_moronic_post_previews(){ | |
var auths = document.getElementsByClassName('auth'); | |
var l = auths.length; | |
var list = map(morons, x => '(by ' + x + ')'); | |
for (var i = 0; i < l;){ | |
var auth = auths[i]; | |
var name = auth.innerHTML; | |
if (list.indexOf(name) < 0){ | |
i++; | |
continue; | |
} | |
auth.parentNode.innerHTML = 'something moronic some moron said'; | |
l--; | |
} | |
} | |
remove_moronic_posts(); | |
remove_moronic_post_previews(); |
Because I didn't know about it. I hack C++, not JS.
Fair enough.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm curious as to why you implemented your own map function instead of using the one JS provides. (Array.prototype.map, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)