Lolz Comment Toggle

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);
        });
    });
})();