Last active
February 15, 2021 19:20
-
-
Save jlamoree/51a3cd39962a89f93577ef03805fb7a0 to your computer and use it in GitHub Desktop.
A Tampermonkey® Userscript to correct page content.
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 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