3 ms·
> write a userscript for Chrome that will replace every occurance of a word1 with word2 here's the script from ChatGPTs response: // ==UserScript== //
by Tepix 4y ago
> write a userscript for Chrome that will replace every occurance of a word1 with word2
here's the script from ChatGPTs response:
// ==UserScript==
// @name Replace Word1 with Word2
// @namespace your-namespace
// @version 1.0
// @description Replaces every occurrence of word1 with word2
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const word1 = "Open AI";
const word2 = '"Open" AI';
const regex = new RegExp(word1, "g");
document.body.innerHTML = document.body.innerHTML.replace(regex, word2);
})();
Need help installing a chrome userscript? Check the multiple answers at
https://stackoverflow.com/questions/5258989/manually-adding-a-userscript-to-google-chrome https://stackoverflow.com/questions/5258989/manually-adding-...
PS I don't use Chrome myself.
- xchkr1337 4y agoreassigning document.body.innerHTML like that seems like a really bad idea, this should be done using MutationObserver
- kevincox 4y agoYup. It will recreate all elements. At the very least it will break event listeners which will break most sites. It will probably do about 8 other things that break many sites.