NGA Re-collapse Button

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

目前為 2017-04-01 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 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    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));

})();