☰

E-Hentai Comment Collapser

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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