Greasy Fork

Greasy Fork is available in English.

LztStreamerMode

Режим стримера для Lolzteam

当前为 2023-09-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         LztStreamerMode
// @namespace    http://tampermonkey.net/
// @version      0.9
// @description  Режим стримера для Lolzteam
// @author       vuchaev2015
// @match        https://zelenka.guru/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru
// @run-at       document-start
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// ==/UserScript==

window.onload = function() {
    var newLi = document.createElement('li');
    newLi.style.cssText = 'display: flex; align-items: center; justify-content: center';

    var newInput = document.createElement('input');
    Object.assign(newInput, { type: 'checkbox', name: 'hide_banner', value: '1', id: 'ctrl_streamer_mode' });

    var newLabel = document.createElement('label');
    Object.assign(newLabel, { htmlFor: 'ctrl_streamer_mode', textContent: 'LZT Streamer Mode' });

    newLi.append(newInput, newLabel);

    var accountMenu = document.querySelector('#AccountMenu > ul > li:nth-child(1) > a');

    if (accountMenu) {
        accountMenu.parentNode.insertBefore(newLi, accountMenu.nextSibling);

        var savedValue = GM_getValue('lztstreamermode');
        if (savedValue === undefined) {
            GM_setValue('lztstreamermode', false);
            savedValue = false;
        }
        newInput.checked = savedValue;

        newInput.addEventListener('change', function() {
            GM_setValue('lztstreamermode', this.checked);
            location.reload();
        });
    }
}

console.log(`Текущее значение lztstreamermode: ${GM_getValue('lztstreamermode')}`)

if (GM_getValue('lztstreamermode', true)) {
    const selectors = [
        "#ConversationListItems",
        "#AlertPanels",
        "#AccountMenu > ul > li.Popup.PopupInPopup.DisableHover > a > span.left",
    ];

    const applyBlur = (selector, trigger = 'hover', ignoredSelectors = []) => {
        const elements = document.querySelectorAll(selector);

        const changeVisibility = (el, visible) => {
            el.style.visibility = visible ? "visible" : "hidden";
        };

        const toggleBlur = (el) => {
            el.style.filter = el.style.filter.includes("blur") ? "none" : "blur(5px)";
        };

        elements.forEach((el) => {
            if (el.classList.contains("blurred")) return;

            if (trigger === 'hidden') {
                changeVisibility(el, false);
                return;
            }

            el.style.filter = "blur(5px)";
            el.classList.add("blurred");

            const isIgnored = (target) =>
            ignoredSelectors.some((selector) => target.matches(selector));

            if (trigger === 'click') {
                el.addEventListener("click", () => {
                    if (!isIgnored(event.target)) toggleBlur(el);
                });
            } else {
                el.addEventListener("mouseover", () => {
                    if (!isIgnored(event.target)) el.style.filter = "none";
                });
                el.addEventListener("mouseout", () => {
                    if (!isIgnored(event.target)) el.style.filter = "blur(5px)";
                });
            }
        });
    };

    function applyBlurIfMatchesUrl(url, selector, trigger) {
        if (window.location.href.startsWith(url)) {
            applyBlur(selector, trigger);
        }
    }

    function changeInputType(selector) {
        var inputElements = document.querySelectorAll(selector);
        for (var i = 0; i < inputElements.length; i++) {
            inputElements[i].type = 'password';
        }
    }

    function applyBlurToBBCodeHide(selector, trigger) {
        const elements = document.querySelectorAll(selector);

        elements.forEach((el) => {
            if (el.classList.contains("blurred")) return;

            const quote = el.querySelector("div.quote");
            const quoteContainer = el.querySelector(
                "blockquote.quoteContainer.hideContainer"
            );
            const attribution = el.querySelector("aside > div.attribution.type");

            if (quote && quoteContainer && attribution) {
                quote.style.filter = "blur(5px)";
                el.classList.add("blurred");

                if (trigger === 'click') {
                    quoteContainer.addEventListener("click", function (event) {
                        if (event.target === quoteContainer) {
                            quote.style.filter = quote.style.filter.includes("blur")
                                ? "none"
                            : "blur(5px)";
                        }
                    });

                    quote.addEventListener("click", function (event) {
                        if (event.target === quote) {
                            quote.style.filter = quote.style.filter.includes("blur")
                                ? "none"
                            : "blur(5px)";
                        }
                    });
                } else {
                    quoteContainer.addEventListener("mouseenter", () => { quote.style.filter = "none"; });
                    quoteContainer.addEventListener("mouseleave", () => { quote.style.filter = "blur(5px)"; });
                }
            }
        });
    }

    const applyBlurToAllSelectors = () =>
    selectors.forEach((selector) => {
        if (selector === ".bbCodeHide") {
            applyBlurToBBCodeHide(selector, "click");
        } else {
            applyBlur(selector);
        }
    });

    const hideInboxElement = () => {
        const selectors = ['.thread_view input.InlineModCheck.item', '.thread_view .modLink.navLink'];
        selectors.forEach(selector => {
            const element = document.querySelector(selector);
            if (element) {
                element.classList.add('hidden');
            }
        });
    };

    const observer = new MutationObserver(mutationsList => {
        for (const mutation of mutationsList) {
            if (mutation.type === 'childList') {
                const affectedNodes = Array.from(mutation.addedNodes).concat(Array.from(mutation.removedNodes));
                if (affectedNodes.some(node => node.matches && node.matches(selectors.join(', ')))) {
                    hideInboxElement();
                    break;
                }
            }
        }
    });

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

    document.addEventListener("DOMContentLoaded", () => {
        applyBlurToAllSelectors();
        applyBlurIfMatchesUrl("https://zelenka.guru/account/security", "#ctrl_email", "click");
        applyBlurIfMatchesUrl("https://zelenka.guru/account/alerts", ".alertGroup ol", "hover");

        const observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                    changeInputType('input[name="secret_answer"]');
                    applyBlurToBBCodeHide('.bbCodeHide', "click");
                    applyBlur('[id^="imn-XenForoUniq"] span.message');
                    applyBlur('.liveAlert.listItemText li[id^="alert"]');
                    applyBlur('.scrollable.scrollable-vertical.lztng-lgi902:not(:has(.userAc-inner.lztng-1rks6og))', "click", [".chat2-tag.lztng-1hpx4rn", ".scrollable-y.lztng-lgi902"]);
                    applyBlur('#ConversationsMenu > div.scroll-wrapper.listPlaceholder.Scrollbar.scrollbar-macosx.scrollbar-dynamic');
                }
            });
        });

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