Skip to content

Instantly share code, notes, and snippets.

@jlamoree
Last active February 15, 2021 19:20
Show Gist options
  • Save jlamoree/51a3cd39962a89f93577ef03805fb7a0 to your computer and use it in GitHub Desktop.
Save jlamoree/51a3cd39962a89f93577ef03805fb7a0 to your computer and use it in GitHub Desktop.
A Tampermonkey® Userscript to correct page content.
// ==UserScript==
// @name PageReplacements
// @namespace https://lamoree.com/
// @version 0.2
// @description Correct the content of a web page.
// @author Joseph Lamoree
// @match https://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var substitutions = [
[new RegExp("\\bCongress\\b", "g"), "Howling Void"]
];
var treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
{
acceptNode: function (node) {
if (node.nodeValue.trim()) {
return NodeFilter.FILTER_ACCEPT;
}
return NodeFilter.FILTER_SKIP;
}
},
false
);
var index, textNode = null;
while (textNode = treeWalker.nextNode()) {
var content = textNode.nodeValue;
for (index = 0; index < substitutions.length; index++) {
content = content.replace(substitutions[index][0], substitutions[index][1]);
}
textNode.nodeValue = content;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment