Greasy Fork 还支持 简体中文。

NGA Re-collapse Button

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NGA Re-collapse Button
// @namespace    https://greasyfork.org/zh-CN/scripts/28612-nga-re-collapse-button
// @version      1.2.0.20180312
// @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      https://greasyfork.org/scripts/39014-nga-user-script-loader/code/NGA%20User%20Script%20Loader.js
// ==/UserScript==

//发布地址:http://bbs.ngacn.cc/read.php?tid=11313839

(function(){

    function init($){

        let r = commonui.reCollapseButton = {
            f: function(e, c, n){
                if(r.timer != undefined){
                    clearTimeout(r.timer);
                    delete r.timer;
                }
                let b = e.target,
                    dB = $(b).parent(),
                    dC = dB.next();
                if(dC.html() == ''){
                    $(b).html('-');
                    dC.css({'overflow-y':'hidden','transition':'all 0.5s ease-in-out','-o-transition':'all 0.5s ease-in-out','-moz-transition':'all 0.5s ease-in-out','-webkit-transition':'all 0.5s ease-in-out','-ms-transition':'all 0.5s ease-in-out','max-height':'0px','opacity':'0'});
                    dB.css('background', __COLOR.border2);
                    let t = $.now();
                    r.mo[t] = new MutationObserver(function(){
                        setTimeout(function(){
                            $('<div />').append(dC.contents()).appendTo(dC);
                            dC.css({'max-height':(dC.children().outerHeight(true) + 'px'),'opacity':'1'});
                            r.timer = setTimeout(function(){
                                dC.css({'max-height':'none'});
                                delete r.timer;
                            }, 500);
                            r.mo[t].disconnect();
                            delete r.mo[t];
                        },100);
                    });
                    r.mo[t].observe(dC[0], {
                        childList: true,
                        subtree: true,
                    });
                    ubbcode.collapse.load(dC[0], c, n);
                    return;
                }
                if($(b).html() == '+'){
                    $(b).html('-');
                    dB.css('background', __COLOR.border2);
                    dC.children().css('display', '');
                    dC.css({'max-height':(dC.children().outerHeight(true) + 'px'),'opacity':'1'});
                    r.timer = setTimeout(function(){
                        dC.css({'max-height':'none'});
                        delete r.timer;
                    }, 500);
                }
                else{
                    $(b).html('+');
                    dB.css('background', '');
                    dC.css('max-height', (dC.children().outerHeight(true) + 'px'));
                    setTimeout(function(){
                        dC.css({'max-height':'0px','opacity':'0'});
                    }, 10);
                    r.timer = setTimeout(function(){
                        dC.children().css('display', 'none');
                        delete r.timer;
                    }, 510);
                }
            },
            r: function(){
                $('.collapse_btn button[onclick^="t"]').each(function(i, b){
                    b = $(b);
                    b.attr('onclick', b.attr('onclick').replace(/^t.+,"/, 'commonui.reCollapseButton.f(event,"'));
                    b.css({width:'1.2em', height:'1.2em', padding:'0', outline:'none', 'font-family':'Serif', 'line-height':'1.1em'});
                });
            },
            mo: {
                body : new MutationObserver(function(){
                    r.r();
                })
            }
        };

        r.r();

        r.mo.body.observe($('body')[0], {
            childList: true,
            subtree: true,
        });

    }

    (function check(){
        try{
            init(commonui.userScriptLoader.$);
        }
        catch(e){
            setTimeout(check, 50);
        }
    })();

})();