Greasy Fork 还支持 简体中文。

Lolz.live Icon Replacer

Заменяет иконки без смещения + настройки замены (круглые или квадратные)

目前為 2025-04-08 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Lolz.live Icon Replacer
// @namespace    http://tampermonkey.net/
// @version      1.7
// @description  Заменяет иконки без смещения + настройки замены (круглые или квадратные)
// @author       eretly
// @match        https://lolz.live/*
// @match        https://lzt.market/*
// @license      MIT
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // НАСТРОЙКИ
    const YOUR_IMAGE_URL = "https://cspromogame.ru//storage/upload_images/avatars/1309.jpg";
    const OTHERS_IMAGE_URL = "https://avatars.dzeninfra.ru/get-zen_doc/2419806/pub_62405301471f227ab529eff5_6240557718cfc01044432b7c/scale_1200";
    const YOUR_USERNAME = "LouiseFrancoise";
    const REPLACE_MODE = 1; // 1=у себя и у других, 2=только у себя, 3=все кроме себя
    const USE_DIFFERENT_ICON_FOR_OTHERS = true; // true - заменяет иконку у других на изображение с OTHERS_IMAGE_URL
    const ROUNDED_STYLE = true; // true - круглые иконки, false - квадратные

    const IMG_STYLE = `
        width: 16px;
        height: 16px;
        vertical-align: middle;
        margin-left: 3px;
        display: inline !important;
        object-fit: cover;
        ${ROUNDED_STYLE ? 'border-radius: 50%;' : ''}
    `;

    function getUsername(element) {
        const usernameElement = element.closest('[class*="username"]') ||
                              element.closest('.message-userDetails') ||
                              element.closest('.memberHeader');

        if (usernameElement) {
            const span = usernameElement.querySelector('span:not([class*="icon"]):not([class*="arrow"])');
            if (span) return span.textContent.trim();

            const link = usernameElement.querySelector('a[href*="/members/"]');
            if (link) return link.textContent.trim();
        }

        let parent = element.parentElement;
        while (parent) {
            if (parent.textContent.includes(YOUR_USERNAME)) {
                const match = parent.textContent.match(/[^\s]+/);
                return match ? match[0] : null;
            }
            parent = parent.parentElement;
        }

        return null;
    }

    function replaceIcons() {
        document.querySelectorAll('.uniqUsernameIcon').forEach(el => {
            if (!el.dataset.replaced) {
                const username = getUsername(el);
                const isCurrentUser = YOUR_USERNAME && username && username.includes(YOUR_USERNAME);

                let shouldReplace = false;
                let imageUrl = YOUR_IMAGE_URL;

                switch (REPLACE_MODE) {
                    case 1:
                        shouldReplace = true;
                        if (USE_DIFFERENT_ICON_FOR_OTHERS && !isCurrentUser) {
                            imageUrl = OTHERS_IMAGE_URL;
                        }
                        break;
                    case 2:
                        shouldReplace = isCurrentUser;
                        break;
                    case 3:
                        shouldReplace = !isCurrentUser;
                        if (USE_DIFFERENT_ICON_FOR_OTHERS) {
                            imageUrl = OTHERS_IMAGE_URL;
                        }
                        break;
                }

                if (shouldReplace) {
                    const img = new Image();
                    img.src = imageUrl;
                    img.style = IMG_STYLE;
                    img.alt = "";

                    el.parentNode.insertBefore(img, el);
                    el.remove();
                    el.dataset.replaced = "true";
                }
            }
        });
    }

    replaceIcons();

    const observer = new MutationObserver(replaceIcons);
    observer.observe(document, { childList: true, subtree: true });

    window.addEventListener('load', () => {
        setTimeout(replaceIcons, 1000);
        setTimeout(replaceIcons, 3000);
    });
})();