Last active
May 4, 2024 12:33
-
-
Save AFCMS/33009c1b85bc4d9ea4b0a2b16f3d57ae to your computer and use it in GitHub Desktop.
Quoicoubeh Tampermonkey Userscript
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 Quoicoubeh | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-01-04 | |
// @description Extend any word ending by quoi with quoicoubeh. | |
// @author AFCM + ChatGPT | |
// @match *://*/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const excludedElements = ['img']; | |
function isExcluded(node) { | |
if (node.nodeType === Node.ELEMENT_NODE) { | |
const tagName = node.tagName.toLowerCase(); | |
return excludedElements.includes(tagName); | |
} | |
return false; | |
} | |
function modifyTextContent(node) { | |
// Replace occurrences of words ending with "quoi" | |
node.nodeValue = node.nodeValue.replace(/\b(\w*quoi)\b/ig, '$1coubeh'); | |
} | |
function traverseAndModify(node) { | |
if (!isExcluded(node)) { | |
if (node.nodeType === Node.TEXT_NODE) { | |
modifyTextContent(node); | |
} else if (node.nodeType === Node.ELEMENT_NODE) { | |
for (const childNode of node.childNodes) { | |
// Recursively traverse child nodes | |
traverseAndModify(childNode); | |
} | |
} | |
} | |
} | |
function observeChanges() { | |
const observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
for (const addedNode of mutation.addedNodes) { | |
traverseAndModify(addedNode); | |
} | |
}); | |
}); | |
const observerConfig = { childList: true, subtree: true }; | |
observer.observe(document.body, observerConfig); | |
} | |
// Initial modification | |
traverseAndModify(document.body); | |
// Observe changes in the DOM and modify dynamically | |
observeChanges(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment