PixelDrain Bypass URLs Globally

Convert all Original Pixeldrain Links to pd for Bypassing in any Page even Linked Buttons.

// ==UserScript==
// @name         PixelDrain Bypass URLs Globally
// @namespace    SWScripts
// @version      v1.1
// @description  Convert all Original Pixeldrain Links to pd for Bypassing in any Page even Linked Buttons.
// @grant        none
// @license      MIT
// @run-at       document-end
// @match        *://*/*
// ==/UserScript==

(function() {
    'use strict';

    const PIXELDRAIN_URL = /pixeldrain\.com\/u\//g;
    const REPLACEMENT_URL = 'pd.cybar.xyz';

    function replaceTextInNode(node) {
        if (node.nodeType === Node.TEXT_NODE) {
            if (PIXELDRAIN_URL.test(node.textContent)) {
                node.textContent = node.textContent.replace(PIXELDRAIN_URL, REPLACEMENT_URL);
            }
        } else if (node.nodeType === Node.ELEMENT_NODE) {
            node.childNodes.forEach(replaceTextInNode);
        }
    }

    function checkAndReplaceText() {
        replaceTextInNode(document.body);
    }

    function handleMutations(mutations) {
        mutations.forEach(mutation => {
            if (mutation.type === 'childList') {
                mutation.addedNodes.forEach(node => {
                    replaceTextInNode(node);
                });
            }
        });
    }

    function observeDOMChanges() {
        const observer = new MutationObserver(handleMutations);
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    document.addEventListener('DOMContentLoaded', function() {
        checkAndReplaceText();
        observeDOMChanges();
    });

    setInterval(checkAndReplaceText, 5000);
})();