Created
April 15, 2021 02:38
-
-
Save caguiclajmg/0c9ac90df41ea2f8f7670e2dedaa9dde to your computer and use it in GitHub Desktop.
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 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