NGA Re-collapse Button

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

Od 01.04.2017.. Pogledajte najnovija verzija.

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         NGA Re-collapse Button
// @namespace    none
// @version      0.0.1.20170401
// @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));

})();