☰

E-Hentai Comment Collapser

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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