Dynamic and Static Text Replacer for voxiom.io

Replace specified text on voxiom.io, including static and dynamic content

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Dynamic and Static Text Replacer for voxiom.io
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Replace specified text on voxiom.io, including static and dynamic content
// @author       You
// @match        https://voxiom.io/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Define the text to search for and replace with
    const searchterm = 'yourName';
    const replaceterm = 'customName';

    // Function to escape special characters in the search term for use in RegExp
    function escapeRegExp(string) {
        return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
    }

    // Function to replace text in a given node
    function replaceTextInNode(node) {
        if (node.nodeType === Node.TEXT_NODE) {
            // Skip script and style tags to avoid breaking the page
            if (node.parentNode && node.parentNode.tagName !== 'SCRIPT' && node.parentNode.tagName !== 'STYLE') {
                node.nodeValue = node.nodeValue.replace(new RegExp(escapeRegExp(searchterm), 'g'), replaceterm);
            }
        } else if (node.nodeType === Node.ELEMENT_NODE) {
            // Handle input elements
            if (node.tagName === 'INPUT' && ['text', 'search', 'password', 'email', 'url'].includes(node.type)) {
                node.value = node.value.replace(new RegExp(escapeRegExp(searchterm), 'g'), replaceterm);
            }
            // Recurse into child nodes
            node.childNodes.forEach(replaceTextInNode);
        }
    }

    // Function to perform replacement on the entire document
    function replaceAllText() {
        replaceTextInNode(document.body);
    }

    // Run initial replacement after a short delay to ensure DOM is fully loaded
    setTimeout(replaceAllText, 1000);

    // Set up MutationObserver to handle dynamic content
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            mutation.addedNodes.forEach(function(node) {
                replaceTextInNode(node);
            });
        });
    });

    // Configure observer to watch for changes in the entire document
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();