NGA 折叠内容展开后可再次收起
当前为
// ==UserScript==
// @name NGA Re-collapse Button
// @namespace https://greasyfork.org/zh-CN/scripts/28612-nga-re-collapse-button
// @version 1.1.1.20180215
// @icon http://bbs.nga.cn/favicon.ico
// @description NGA 折叠内容展开后可再次收起
// @author AgLandy
// @include /^https?://(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/.+/
// @grant none
// ==/UserScript==
//发布地址:http://bbs.ngacn.cc/read.php?tid=11313839
if(typeof jQuery == 'undefined'){
let s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js';
s.onload = s.onreadystatechange = function(){
if(!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState){
main(jQuery.noConflict());
this.onload = this.onreadystatechange = null;
}
};
document.head.appendChild(s);
}
else
main(jQuery);
function main($Q){
if(!window.commonui)
commonui = {};
let r = commonui.reCollapseButton = {};
r.f = function(e, c, n){
if(r.timer != undefined){
clearTimeout(r.timer);
delete r.timer;
}
let b = e.target, dB = $Q(b).parent(), dC = dB.next();
if(dC.html() == ''){
$Q(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);
ubbcode.collapse.load(dC[0], c, n);
setTimeout(function(){
$Q('<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);
}, 100);
return;
}
if($Q(b).html() == '+'){
$Q(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{
$Q(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);
}
};
let 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.+,"/, 'commonui.reCollapseButton.f(event,"'));
$Q(c[i]).children('button').css({width:'1.2em', height:'1.2em', padding:'0', outline:'none', 'font-family':'Serif', 'line-height':'1.1em'});
}
}