Roblox - Replace "Connections" and "Connect" with "Friends"

Replaces "Connections" and "Connect" with "Friends" on Roblox, including page title

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Roblox - Replace "Connections" and "Connect" with "Friends"
// @namespace    https://roblox.com
// @version      1.01
// @description  Replaces "Connections" and "Connect" with "Friends" on Roblox, including page title
// @author       Synocism
// @license     MIT
// @match        https://www.roblox.com/*
// @grant        none
// ==/UserScript==

(function() {
    function replaceText() {
        const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
        let node;
        while ((node = walker.nextNode())) {
            // Replace exact matches
            node.nodeValue = node.nodeValue
                .replace(/\bConnections\b/g, "Friends")
                .replace(/\bConnect\b/g, "Friends")
            .replace(/\bAdd Connection\b/g, "Add Friend")
            .replace(/\Remove Connection\b/g, "Remove Friend")
            .replace(/\bSearch Connections\b/g, "Search Friends");
        }
    }

    function replaceTitle() {
        if (document.title.includes("Connections")) {
            document.title = document.title.replace("Connections", "Friends");
        }
        if (document.title.includes("Connect")) {
            document.title = document.title.replace("Connect", "Friends");
        }
    }

    // Initial run
    replaceText();
    replaceTitle();

    // Rerun on DOM changes
    const observer = new MutationObserver(() => {
        replaceText();
        replaceTitle();
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();