E-Hentai Comment Collapser

Hidden comment score < 0.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         E-Hentai Comment Collapser
// @namespace    https://greasyfork.org/users/1069880-l-l
// @version      1.0
// @description  Hidden comment score < 0.
// @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
// @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;
    }

    // 获取所有带有 class="c1" 的元素
    var c1Elements = document.getElementsByClassName("c1");

    // 遍历所有 c1Elements 元素
    for (var i = 0; i < c1Elements.length; i++) {
        var c1Element = c1Elements[i];

        // 查找每个 c1 元素内部的 score 元素
        var scoreElement = c1Element.querySelector(".c5 span");

        if (scoreElement) {
            // 获取 score 的文本内容并转换为整数
            var score = parseInt(scoreElement.innerText.trim(), 10);

            if (score < 0) {
                // 1. 获取评论内容区域 (.c6)
                var contentElement = c1Element.querySelector(".c6");
                if (contentElement) {
                    // 默认隐藏评论内容
                    contentElement.style.display = "none";
                }

                // 2. 略微降低整体的透明度
                c1Element.style.opacity = "0.6";

                // 3. 添加按钮
                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);
                }
            }
        }
    }
})();