when running this userscript, which simply finds and replaces certain letters and words, it doesn't replace the main texts, and only replaces text that is loaded after the webpage has been fully loaded. how can i make it replace all text on a webpage? i've tried all the different @run-at
types but nothing has worked so far.
// ==UserScript==
// @name OwO Script
// @namespace
// @version 0.2
// @description
// @author You
// @match *://*/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
let rules = [
['\\blove\\b', 'wuv'],
['\\bmr\\b', 'mister'],
['\\bbathroom\\b', 'potty'],
['\\bdog\\b', 'doggo'],
['\\bcat\\b', 'kitteh'],
['\\bhell\\b', 'heck'],
['\\bfuck|\\bfuk', 'frick'],
['\\bshit', 'shoot'],
['\\bfriend\\b', 'frend'],
['\\bstop\\b', 'stawp'],
['[rl]', 'w']
]
let suffixes = [
'(ノ´ з `)ノ',
'( ´ ▽ ` ).。o♡',
'(´,,•ω•,,)♡',
':3',
'>:3',
'OwO',
'uwu',
'hehe',
'xox',
'>3<',
'murr~',
'UwU',
'-3-',
'c:',
'*nuzzles*',
'*waises paw*',
'*notices bulge*'
]
function recurse (node) {
if (node.nodeValue == null) {
for (let child of node.childNodes) {
recurse(child)
}
} else if (node.nodeType === 3) {
let text = node.nodeValue
for (let [find, replace] of rules) {
text = text.replace(RegExp(find, 'g'), replace)
text = text.replace(RegExp(find.toUpperCase().replace(/\\B/g, '\\b'), 'g'), replace.toUpperCase())
}
if (Math.random() < 0.2) {
text += ` ${suffixes[Math.floor(Math.random() * suffixes.length)]}`
}
node.nodeValue = text
}
}
document.body.addEventListener('DOMNodeInserted', event => {
recurse(event.target)
})
})()