Discord Modifications

Customizable Discord :l

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Discord Modifications
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Customizable Discord :l
// @author       Unknown Hacker
// @license      CC BY-NC
// @match        https://discord.com/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    const defaultIconURL = "/assets/28f89b5f78dd6f80.webp";
    const defaultTitle = "Discorda!";

    let iconURL = GM_getValue("iconURL", defaultIconURL);
    let customTitle = GM_getValue("customTitle", defaultTitle);

    GM_registerMenuCommand("Set Icon URL", () => {
        const newIconURL = prompt("Enter new icon URL:", iconURL);
        if (newIconURL) {
            GM_setValue("iconURL", newIconURL);
            location.reload();
        }
    });

    GM_registerMenuCommand("Set Custom Title", () => {
        const newTitle = prompt("Enter new page title:", customTitle);
        if (newTitle) {
            GM_setValue("customTitle", newTitle);
            location.reload();
        }
    });

    const appIconHTML = `<img src="${iconURL}" width="48" alt="App Icon" draggable="false">`;

    function hasTextContent(element) {
        return element.textContent.trim().length > 0;
    }

    function insertIcon() {
        const elements = document.querySelectorAll('.childWrapper__6e9f8.childWrapperNoHoverBg__6e9f8');

        elements.forEach((element) => {
            if (!element.querySelector(`img[src="${iconURL}"]`) && !hasTextContent(element)) {
                element.insertAdjacentHTML('beforeend', appIconHTML);
            }
        });
    }

    function updateTitle() {
        if (document.title !== customTitle) {
            document.title = customTitle;
        }
    }

    insertIcon();
    updateTitle();

    const observer = new MutationObserver(() => {
        insertIcon();
        updateTitle();
    });

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