☰

E-Hentai Comment Collapser

Optional hidden comment score <0 and show author comments only.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

Um dieses Skript zu installieren, müssen Sie eine Erweiterung wie Tampermonkey oder Violentmonkey installieren.

Um dieses Skript zu installieren, müssen Sie eine Erweiterung wie Tampermonkey oder Violentmonkey installieren.

Um dieses Skript zu installieren, müssen Sie eine Erweiterung wie Tampermonkey oder Userscripts installieren.

Um dieses Skript zu installieren, müssen Sie eine Erweiterung wie Tampermonkey installieren.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

Um dieses Design zu installieren, müssen Sie eine Erweiterung wie Stylus installieren.

Um dieses Design zu installieren, müssen Sie eine Erweiterung wie Stylus installieren.

Um dieses Design zu installieren, müssen Sie eine Erweiterung wie Stylus installieren.

Um diesen Stil zu installieren, müssen Sie eine Erweiterung für den Benutzerstil Verwaltung installieren.

Um diesen Stil zu installieren, müssen Sie eine Erweiterung für den Benutzerstil Verwaltung installieren.

Um diesen Stil zu installieren, müssen Sie eine Erweiterung für den Benutzerstil Verwaltung installieren.

(Ich habe bereits einen Benutzerstil Verwaltung, ich möchte ihn installieren!)

// ==UserScript==
// @name         E-Hentai Comment Collapser
// @namespace    https://greasyfork.org/users/1069880-l-l
// @version      1.1
// @description  Optional hidden comment score <0 and show author comments only.
// @author       Li
// @match        https://e-hentai.org/*
// @match        https://exhentai.org/*
// @icon         https://www.google.com/s2/favicons?domain=e-hentai.org
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-end
// @license      MIT
// ==/UserScript==

// thanks:
// https://greasyfork.org/scripts/450620 (MIT)(greasyfork.org/users/316903-fmnijk)

/* main function */
(function() {
    'use strict';

    if (window.location.href === 'https://e-hentai.org/'){
        return false;
    }

    // ----- 作者评论过滤 -----
    var authorEl = document.querySelector('#gdn a[href*="/uploader/"]') ||
                   document.querySelector('#gmid a[href*="/uploader/"]');
    var authorName = authorEl ? authorEl.textContent.trim() : null;

    if (authorName) {
        var SKEY = 'eh_author_only';
        var showAuthorOnly = GM_getValue(SKEY, false);

        var cdiv = document.getElementById('cdiv');
        var commentList = [];
        if (cdiv) {
            commentList = Array.prototype.map.call(cdiv.querySelectorAll('.c1'), function(c) {
                var a = c.querySelector('.c3 a[href*="/uploader/"]');
                return { el: c, author: a ? a.textContent.trim() : null };
            });
        }

        var setFilter = function(enable) {
            showAuthorOnly = enable;
            GM_setValue(SKEY, enable);
            commentList.forEach(function(item) {
                var isAuthorComment = item.author === authorName;
                item.el.style.display = (!enable || isAuthorComment) ? '' : 'none';
            });
            btn.textContent = enable ? 'Show All Comments' : 'Author Comments Only';
        };

        // 切换控件
        var btn = document.createElement('a');
        btn.href = 'javascript:void(0);';
        btn.textContent = showAuthorOnly ? 'Show All Comments' : 'Author Comments Only';
        btn.onclick = function() { setFilter(!showAuthorOnly); };

        var toolbar = document.createElement('p');
        toolbar.textContent = '[';
        toolbar.appendChild(btn);
        toolbar.appendChild(document.createTextNode(']'));
        cdiv.insertBefore(toolbar, cdiv.firstChild);

        if (showAuthorOnly) {
            setFilter(true);
        }
    }

    // ----- 负分评论折叠 -----
    var c1Elements = document.getElementsByClassName("c1");

    for (var i = 0; i < c1Elements.length; i++) {
        var c1Element = c1Elements[i];

        var scoreElement = c1Element.querySelector(".c5 span");

        if (scoreElement) {
            var score = parseInt(scoreElement.innerText.trim(), 10);

            if (score < 0) {
                var contentElement = c1Element.querySelector(".c6");
                if (contentElement) {
                    contentElement.style.display = "none";
                }

                c1Element.style.opacity = "0.6";

                var c3Element = c1Element.querySelector(".c3");
                if (c3Element) {
                    var toggleBtn = document.createElement("a");
                    toggleBtn.href = "javascript:void(0);";
                    toggleBtn.innerText = " [Show comment]";
                    toggleBtn.style.color = "#888";
                    toggleBtn.style.cursor = "pointer";
                    toggleBtn.style.marginLeft = "12px";
                    toggleBtn.style.fontWeight = "bold";

                    toggleBtn.onclick = (function(content, container, btn) {
                        return function() {
                            if (content.style.display === "none") {
                                content.style.display = "block";
                                container.style.opacity = "1.0";
                                btn.innerText = " [Hide comment]";
                            } else {
                                content.style.display = "none";
                                container.style.opacity = "0.6";
                                btn.innerText = " [Show comment]";
                            }
                        };
                    })(contentElement, c1Element, toggleBtn);

                    c3Element.appendChild(toggleBtn);
                }
            }
        }
    }
})();