Created
October 20, 2017 12:47
-
-
Save jD91mZM2/a79220b7f7dfa8d2fd2f190f6d701526 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 Find replace! | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description tbodt's idea, but executed poorly | |
// @author You | |
// @match http://*/* | |
// @match https://*/* | |
// @grant none | |
// ==/UserScript== | |
let replace = { | |
// "some key \(may include regex\)": "some value" | |
}; | |
window.onload = function() { | |
let walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false); | |
while (walker.nextNode()) { | |
let node = walker.currentNode; | |
for (let key of Object.keys(replace)) { | |
node.textContent = node.textContent.replace(new RegExp("\\b" + key + "\\b", "gi"), replace[key]); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment