Cartel Empire - ceReplace

Replaces text globally in Cartel Empire (except in chat)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Cartel Empire - ceReplace
// @namespace    cartel.ovh
// @version      1.00
// @description  Replaces text globally in Cartel Empire (except in chat)
// @author       ZoomStop
// @match        https://cartelempire.online/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=cartelempire.online
// @license      MIT 
// ==/UserScript==
//
//  Define replacements below in Replace_Terms
//  On the left put the text to search, on the right put the text to replace the text on the left with
//  Add additional lines as needed following this format:
//  [ "Text To Search For", "Text to Replace With" ],
//

(function() { 'use strict'; 
    
    const Replace_Terms = [
        ["£","$"],
        ["Team 1", "✅ Team 1"],
        ["Team 2", "✅ Team 2"],
        ["Team 3", "✅ Team 3"],
        ["Team 4", "✅ Team 4"],
        ["Team 5", "✅ Team 5"],
    ];

    function replaceStringsOnPage() {
        $('*').contents().each(function () {
            if (this.nodeType === 3) {     
                if ($(this).closest('.chatContainer').length === 0) {
                    var nodeValue = this.nodeValue;
                    Replace_Terms.forEach(function (replacement) {
                        if (!nodeValue.includes(replacement[1])) {
                            nodeValue = nodeValue.replace(new RegExp(replacement[0], 'g'), replacement[1]);
                        }
                    });
                    this.nodeValue = nodeValue;
                }
            }
        });
    }

    function observeMutations() {
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.addedNodes && mutation.addedNodes.length > 0) {
                    mutation.addedNodes.forEach(function(node) {
                        if (node.nodeType === 1 && ($(node).hasClass("modal-backdrop") || $(node).hasClass("offerListWrapper"))) { 
                            replaceStringsOnPage();
                        }
                    });
                }
            });
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    $(document).ready(function() { 
        replaceStringsOnPage();
        observeMutations();
    });
})();