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.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като 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
    });
})();