Greasy Fork

Greasy Fork is available in English.

虎扑评论引用自动折叠

虎扑引用楼层内容过长自动折叠,增加展开和收起按钮

当前为 2018-12-05 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         虎扑评论引用自动折叠
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  虎扑引用楼层内容过长自动折叠,增加展开和收起按钮
// @author       zerozz
// @match        https://bbs.hupu.com/*.html
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function onClickExpand() {
        var ele = document.getElementById("expandBtn" + this.id.charAt(this.id.length - 1));
        if (this.innerText == "展开") {
            this.parentNode.previousElementSibling.style.maxHeight = "none";
            this.innerText = "收起";
        } else {
            this.parentNode.previousElementSibling.style.maxHeight = "100px";
            this.innerText = "展开";
        }
        //this.previousElementSibling.style.cssText='max-height: none; overflow: hidden; transition: max-height 2s ease 0s;';
        console.log(this);
        // this.parentNode.removeChild(this);
    }

    var bqEleArr = document.getElementsByTagName("blockquote") || [];
    var size = bqEleArr.length;
    for (var i = 0; i < size; i++) {
        var bqEle = bqEleArr[i];
        bqEle.style.cssText='max-height: 100px; overflow: hidden; transition: max-height 2s ease 0s;';

        var expandParentEle = document.createElement("div");
        expandParentEle.id = "expandParentEle" + i;
        expandParentEle.style.cssText = "text-align: center;padding: 10px;";

        var expandEle = document.createElement("span");
        expandEle.id = "expandBtn" + i;
        expandEle.style.cssText = "color:#108089;cursor: pointer;padding: 4px 7px;border-radius: 3px;border-width: 1px;border-style: solid;border-color: rgb(166, 166, 166);transition: all 0.1s ease 0s;";
        expandEle.innerText = "展开";
        expandEle.onclick = onClickExpand;
        expandParentEle.appendChild(expandEle);

        var parent = bqEle.parentNode;
        if (parent.lastChild == bqEle) {
            parent.appendChild(expandParentEle);
        } else {
            parent.insertBefore(expandParentEle, bqEle.nextSibling)
        }
    }



})();