Greasy Fork

NGA Re-collapse Button

NGA 折叠内容展开后可再次收起

目前为 2017-04-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         NGA Re-collapse Button
// @namespace    https://greasyfork.org/zh-CN/scripts/28612-nga-re-collapse-button
// @version      0.0.1.20170402
// @icon         http://bbs.nga.cn/favicon.ico
// @description  NGA 折叠内容展开后可再次收起
// @author       AgLandy
// @include      /^https?://(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/.+/
// @grant        none
// @require      http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
// ==/UserScript==

var $Q = jQuery.noConflict();

(function(){

    var c = $Q('.collapse_btn');
    for(i = 0; c.length > i; i++){
        var t = $Q(c[i]).children('button').attr('onclick');
        $Q(c[i]).children('button').attr('onclick', t.replace(t.substr(0, t.search(/,/)), 'cBtnClick(event'));
        $Q(c[i]).children('button').css({width:'18px', padding:'0', 'text-decoration':'none', outline:'none'});
        $Q(c[i]).html($Q(c[i]).html().replace(/点击显示隐藏的内容/, '点击显示折叠的内容').replace(/<\/button>/, '</button><div style="display:inline">') + '</div><div style="display:inline"></div>');
    }

    var sc = "\
    function cBtnClick(e, c, n){\
        var b = e.target;\
        if(b.parentNode.nextSibling.innerHTML == ''){\
            ubbcode.collapse.load(b.parentNode.nextSibling, c, n);\
            b.innerHTML = '-';\
            b.nextSibling.style.display = 'none';\
            b.nextSibling.nextSibling.innerHTML = ' 点击收起折叠的内容 ...';\
            return;\
        }\
        if(b.innerHTML == '+'){\
            b.innerHTML = '-';\
            b.nextSibling.style.display = 'none';\
            b.parentNode.nextSibling.setAttribute('style', 'display:block');\
            b.nextSibling.nextSibling.style.display = 'inline';\
        }\
        else{\
            b.innerHTML = '+';\
            b.nextSibling.style.display = 'inline';\
            b.parentNode.nextSibling.setAttribute('style', 'display:none');\
            b.nextSibling.nextSibling.style.display = 'none';\
        }\
    }";

    $Q('head').append($Q('<script type="text/javascript" />').html(sc));

})();