Lolz.live Icon Replacer / Deleter

Удаляет иконки или заменяет их на кастомные с настройками

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Lolz.live Icon Replacer / Deleter
// @namespace    http://tampermonkey.net/
// @version      2.1
// @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 = "KusuriYakuzen";
    const REPLACE_MODE = 1; // 1=у себя и у других, 2=только у себя, 3=все кроме себя
    const USE_DIFFERENT_ICON_FOR_OTHERS = true; // true - заменяет иконку у других на OTHERS_IMAGE_URL
    const ROUNDED_STYLE = false; // true - круглые иконки, false - квадратные
    const REMOVE_DEFAULT_ICONS = false; // true - удаляет иконки полностью

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

    const getUsername = (el) => {
        const usernameElement = el.closest('[class*="username"], .message-userDetails, .memberHeader');
        if (!usernameElement) return null;

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

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

    const processIcons = () => {
        document.querySelectorAll('.uniqUsernameIcon, .uniqUsernameIcon--custom').forEach(el => {
            if (el.dataset.processed) return;

            const username = getUsername(el);
            const isCurrentUser = 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) {
                if (REMOVE_DEFAULT_ICONS) {
                    el.remove();
                } else {
                    const img = new Image();
                    img.src = imageUrl;
                    img.style = IMG_STYLE;
                    img.alt = "";
                    el.parentNode.insertBefore(img, el);
                    el.remove();
                }
            }

            el.dataset.processed = "true";
        });
    };

    processIcons();

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

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