NGA Re-collapse Button

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

Verze ze dne 23. 04. 2017. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         NGA Re-collapse Button
// @namespace    https://greatest.deepsurf.us/zh-CN/scripts/28612-nga-re-collapse-button
// @version      0.0.3.20170422
// @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==

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

var $Q = jQuery.noConflict();

(function(){

    var c = $Q('.collapse_btn');
    for(i = 0; c.length > i; i++){
        $Q(c[i]).children('button').attr('onclick', $Q(c[i]).children('button').attr('onclick').replace(/^t.+,"/, 'cBtnClick(event,"'));
        $Q(c[i]).children('button').css({width:'1.2em', height:'1.2em', padding:'0', outline:'none', 'font-family':'Serif', 'line-height':'1.1em'});
        $Q(c[i]).html($Q(c[i]).html().replace(/点击显示隐藏的内容/, '点击显示折叠的内容').replace(/<\/button>/, '</button><div style="display:inline">') + '</div><div style="display:none"> 点击收起折叠的内容 ...</div>');
    }

    var sc = "\
    function cBtnClick(e, c, n){\
        var b = e.target;\
        if(b.parentNode.nextSibling.innerHTML == ''){\
            b.innerHTML = '-';\
            b.nextSibling.style.display = 'none';\
            b.nextSibling.nextSibling.style.display = 'inline';\
            ubbcode.collapse.load(b.parentNode.nextSibling, c, n);\
            return;\
        }\
        if(b.innerHTML == '+'){\
            b.innerHTML = '-';\
            b.nextSibling.style.display = 'none';\
            b.nextSibling.nextSibling.style.display = 'inline';\
            b.parentNode.nextSibling.style.display = 'block';\
        }\
        else{\
            b.innerHTML = '+';\
            b.nextSibling.style.display = 'inline';\
            b.nextSibling.nextSibling.style.display = 'none';\
            b.parentNode.nextSibling.style.display = 'none';\
        }\
    }\
    function tlClick(e, n){\
        var i = e.target.parentNode;\
        if(!i.nextSibling.firstChild)\
            eval('i.nextSibling.innerHTML = ubbcode.manualLoadCache[\"' + n + '\"];');\
        i.style.display = 'none';\
        i.nextSibling.style.display = '';\
    }\
    ";

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


    //  ↓  大图与缩略图可相互切换,如不需要,可整段注释掉。

    function tlF(){
        if($Q('.thumblink').next('span').length){
            var tl = $Q('.thumblink');
            $Q('<a href="javascript:void(0)" onclick="this.previousSibling.style.display=\'\';this.style.display=\'none\'">').insertAfter(tl);
            for(i = 0; tl.length > i; i++)
                $Q(tl[i]).attr('onclick', $Q(tl[i]).attr('onclick').replace(/^t.+\[/, 'tlClick(event,').replace(/\].+"none"/, ')'));
        }
    }
    tlF();

    var tlMO = new MutationObserver(function(){
        tlF();
    });

    tlMO.observe(document.body, {
        childList: true,
        subtree: true
    });

    //  ↑  大图与缩略图可相互切换

})();