There was a bug in the previous version with selection not working. This is resolved in the present version. There is also a different set of replacement rules for fun.
// ==UserScript==
// @name Word Filter for leftypol.org
// @namespace http://leftypol.org
// @description Replace words with other words, from textboard.org
// @version 2
// @match *://leftypol.org/*
// @grant none
// ==/UserScript==
'use strict';
var path, pathtype, observer, mutationobserver, replacements, regex, key, textnodes, node, s;
observer = function() {
replacements = {
"(re)?tard(ed)?" : "Kautskyite",
"(?<!\\b)fag" : "comrad",
"PMC" : "labor-aristocrcacy",
"white[\\s-]*collar" : "labor-aristocracy",
"middle[\\s-]*class" : "labor-aristocracy",
"elite" : "bousiousie",
"establishment" : "bousiousie",
"working[\\s-]*class" : "proletariate",
"blue[\\s-]*collar" : "proletariate",
"masses" : "proletariate",
"NEET" : "lumpen-proletariate",
};
regex = {};
for (key in replacements) {
regex[key] = new RegExp(key, 'gi');
}
textnodes = document.evaluate( "//body//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < textnodes.snapshotLength; i++) {
node = textnodes.snapshotItem(i);
s = node.data;
for (key in replacements) {
s = s.replace(regex[key], replacements[key]);
}
node.data = s;
}
}
mutationobserver = new MutationObserver(observer);
path = location.pathname.split("/");
pathtype = path[path.length - 1];
// document.body can't be used to avoid a bug with selection.
if (pathtype == "index.html" || pathtype.match("[0-9]+(\\+50)?.html")) {
mutationobserver.observe(document.getElementsByName("postcontrols")[0], { childList: true, subtree: true });
}
if (pathtype == "catalog.html") {
mutationobserver.observe(document.getElementsByC
Post too long. Click here to view the full text.