Lolz Comment Toggle

Показывать/скрывать комментарии на lolz.live

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Lolz Comment Toggle
// @namespace    https://lolz.live/unique
// @version      1.0
// @description  Показывать/скрывать комментарии на lolz.live
// @author       https://lolz.live/unique
// @license      MIT
// @match        https://lolz.live/*
// @icon         https://lolz.live/favicon.ico
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    function waitForElements(selector, callback) {
        const observer = new MutationObserver(() => {
            const elements = document.querySelectorAll(selector);
            if (elements.length) {
                callback(elements);
                observer.disconnect();
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    waitForElements('.secondaryContent.blockLinksList', (menus) => {
        menus.forEach((menu) => {
            const postContainer = menu.closest('li[id^="profile-post-"], li[id^="post-"]');
            if (!postContainer) return;

            const commentBlock = postContainer.querySelector('.messageResponse');
            const commentBlock2 = postContainer.querySelector('.messageSimple');

            let targetBlock = null;
            let commentElements = [];
            let commentMore = [];

            if (commentBlock) {
                const comments = commentBlock.querySelectorAll('.commentInfo');
                if (comments.length > 0) {
                    targetBlock = commentBlock;
                    commentElements = commentBlock.querySelectorAll('.comment');
                    commentMore = commentBlock.querySelectorAll('.commentMore');
                }
            }

            if (!targetBlock && commentBlock2) {
                const comments2 = commentBlock2.querySelectorAll('.commentInfo');
                if (comments2.length > 0) {
                    targetBlock = commentBlock2;
                    commentElements = commentBlock2.querySelectorAll('.comment');
                    commentMore = commentBlock2.querySelectorAll('.commentMore');
                }
            }

            if (!targetBlock || commentElements.length === 0) return;

            // Скрываем комментарии
            commentElements.forEach(comment => comment.style.display = 'none');
            commentMore.forEach(comment => comment.style.display = 'none');

            // Создаём кнопку
            const showCommentsLi = document.createElement('li');
            const showCommentsBtn = document.createElement('a');
            showCommentsBtn.className = 'commentMore CommentLoader';
            showCommentsBtn.textContent = 'Показать комментарии';
            showCommentsBtn.style.cursor = 'pointer';
            if (commentBlock2) {
                showCommentsBtn.style.marginLeft = '70px';
            }

            let commentsHidden = true;

            showCommentsBtn.addEventListener('click', (e) => {
                e.preventDefault();
                commentsHidden = !commentsHidden;
                commentElements.forEach(comment => comment.style.display = commentsHidden ? 'none' : '');
                commentMore.forEach(comment => comment.style.display = commentsHidden ? 'none' : '');
                showCommentsBtn.textContent = commentsHidden ? 'Показать комментарии' : 'Скрыть комментарии';
            });

            showCommentsLi.appendChild(showCommentsBtn);

            targetBlock.parentElement.insertBefore(showCommentsLi, targetBlock.nextSibling);
        });
    });
})();