Skip to content

Instantly share code, notes, and snippets.

@caguiclajmg
Created April 15, 2021 02:38
Show Gist options
  • Save caguiclajmg/0c9ac90df41ea2f8f7670e2dedaa9dde to your computer and use it in GitHub Desktop.
Save caguiclajmg/0c9ac90df41ea2f8f7670e2dedaa9dde to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name TextReplace
// @namespace https://guarandoo.jp
// @version 0.1
// @description Simple text replacement
// @author [email protected]
// @match https://www.lowendtalk.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const replacements = [
{pattern: new RegExp("EASTER 2021"), replace: 'XXX'},
{pattern: new RegExp("LowEndTalk"), replace: 'YYY'},
];
let walker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
{
acceptNode: node => {
if(node.nodeValue.trim()) return NodeFilter.FILTER_ACCEPT;
return NodeFilter.FILTER_SKIP;
},
},
);
let node = null;
while(node = walker.nextNode()) {
let value = node.nodeValue;
replacements.forEach(repl => value = value.replace(repl.pattern, repl.replace));
node.nodeValue = value;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment