Sharty Mod Icons

Adds Mod Icons

目前為 2024-10-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Sharty Mod Icons
// @namespace    soyjak.party
// @version      1.1
// @license      MIT
// @description  Adds Mod Icons
// @author       Chud
// @match        *://soyjak.party/*
// @match        *://soyjak.st/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Create a style element for CSS
    const style = document.createElement('style');
    style.textContent = `
        .mod-icon {
            background-image: url('https://files.catbox.moe/9u72hu.png');
            width: 20px; /* Set size for the icon */
            height: 20px; /* Set size for the icon */
            display: inline-block;
            vertical-align: middle;
            margin-left: 2px; /* Space between capcode and icon */
            margin-top: -2px; /* Move icon up by 2 pixels */
            background-size: contain; /* Scale the image to fit */
            background-repeat: no-repeat; /* Prevent image from repeating */
            background-position: center; /* Center the image */
            cursor: default; /* Change cursor to default */
        }
        .mod-icon-wrapper {
            display: inline-block; /* Make the wrapper inline */
            cursor: default; /* Change cursor to default */
        }
        .capcode {
            font-weight: bold; /* Make capcode font bold */
        }
    `;
    document.head.appendChild(style);

    // Set to track processed posts
    const processedPosts = new Set();

    // Function to add mod icons to posts
    function addModIcons() {
        document.querySelectorAll('.post').forEach(post => {
            if (processedPosts.has(post)) return; // Skip if already processed

            const capcodeElement = post.querySelector('.capcode');
            const modIcon = post.querySelector('.mod-icon'); // Check if icon already exists

            if (capcodeElement && !modIcon) {
                const capcodeText = capcodeElement.textContent.trim();
                console.log(`Capcode found: ${capcodeText}`); // Debug log

                // Check for "## Mod", "## Admin", or "## Froot"
                if (capcodeText === '## Mod' || capcodeText === '## Admin' || capcodeText === '## Froot') {
                    const iconWrapper = document.createElement('span');
                    iconWrapper.className = 'mod-icon-wrapper'; // Create a wrapper for the icon
                    const newModIcon = document.createElement('span');
                    newModIcon.className = 'mod-icon';

                    // Prevent click propagation
                    newModIcon.addEventListener('click', function(event) {
                        event.stopPropagation();
                    });

                    // Set the icon based on capcode
                    if (capcodeText === '## Admin') {
                        newModIcon.title = "This User does it for Free."; // Tooltip for Admin
                        const nameElement = post.querySelector('.name'); // Find the name element
                        if (nameElement && nameElement.textContent.includes('Chud')) {
                            iconWrapper.appendChild(newModIcon); // Append icon to the wrapper
                            capcodeElement.appendChild(iconWrapper); // Append wrapper next to capcode
                        }
                    } else if (capcodeText === '## Mod') {
                        iconWrapper.appendChild(newModIcon); // Append icon for "## Mod"
                        capcodeElement.appendChild(iconWrapper); // Append wrapper next to capcode
                    } else if (capcodeText === '## Froot') {
                        newModIcon.style.backgroundImage = "url('https://files.catbox.moe/od3szi.png')"; // Set new icon for Froot
                        newModIcon.title = "This User is Fruity."; // Tooltip for Froot
                        iconWrapper.appendChild(newModIcon);
                        capcodeElement.appendChild(iconWrapper);
                    }

                    processedPosts.add(post); // Mark this post as processed
                }
            }
        });
    }

    // Run the function on page load
    addModIcons();

    // Set up a MutationObserver for dynamically loaded posts
    const observer = new MutationObserver(addModIcons);
    observer.observe(document.body, { childList: true, subtree: true });
})();