☰

E-Hentai Comment Collapser

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램을 먼저 설치해야 합니다.

이 스크립트를 설치하려면 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);
                }
            }
        }
    }
})();