Skip to content

Instantly share code, notes, and snippets.

@Helios-vmg
Last active September 30, 2023 12:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Helios-vmg/b2b845a3eec280571e6f34869504c8cf to your computer and use it in GitHub Desktop.
Save Helios-vmg/b2b845a3eec280571e6f34869504c8cf to your computer and use it in GitHub Desktop.
// ==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();
@xyzshantaram
Copy link

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)

@Helios-vmg
Copy link
Author

Because I didn't know about it. I hack C++, not JS.

@xyzshantaram
Copy link

Fair enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment