NGA Re-collapse Button

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

  1. // ==UserScript==
  2. // @name NGA Re-collapse Button
  3. // @namespace https://gf.qytechs.cn/zh-CN/scripts/28612-nga-re-collapse-button
  4. // @version 1.2.0.20180312
  5. // @icon http://bbs.nga.cn/favicon.ico
  6. // @description NGA 折叠内容展开后可再次收起
  7. // @author AgLandy
  8. // @include /^https?://(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/.+/
  9. // @grant none
  10. // @require https://gf.qytechs.cn/scripts/39014-nga-user-script-loader/code/NGA%20User%20Script%20Loader.js
  11. // ==/UserScript==
  12.  
  13. //发布地址:http://bbs.ngacn.cc/read.php?tid=11313839
  14.  
  15. (function(){
  16.  
  17. function init($){
  18.  
  19. let r = commonui.reCollapseButton = {
  20. f: function(e, c, n){
  21. if(r.timer != undefined){
  22. clearTimeout(r.timer);
  23. delete r.timer;
  24. }
  25. let b = e.target,
  26. dB = $(b).parent(),
  27. dC = dB.next();
  28. if(dC.html() == ''){
  29. $(b).html('-');
  30. 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'});
  31. dB.css('background', __COLOR.border2);
  32. let t = $.now();
  33. r.mo[t] = new MutationObserver(function(){
  34. setTimeout(function(){
  35. $('<div />').append(dC.contents()).appendTo(dC);
  36. dC.css({'max-height':(dC.children().outerHeight(true) + 'px'),'opacity':'1'});
  37. r.timer = setTimeout(function(){
  38. dC.css({'max-height':'none'});
  39. delete r.timer;
  40. }, 500);
  41. r.mo[t].disconnect();
  42. delete r.mo[t];
  43. },100);
  44. });
  45. r.mo[t].observe(dC[0], {
  46. childList: true,
  47. subtree: true,
  48. });
  49. ubbcode.collapse.load(dC[0], c, n);
  50. return;
  51. }
  52. if($(b).html() == '+'){
  53. $(b).html('-');
  54. dB.css('background', __COLOR.border2);
  55. dC.children().css('display', '');
  56. dC.css({'max-height':(dC.children().outerHeight(true) + 'px'),'opacity':'1'});
  57. r.timer = setTimeout(function(){
  58. dC.css({'max-height':'none'});
  59. delete r.timer;
  60. }, 500);
  61. }
  62. else{
  63. $(b).html('+');
  64. dB.css('background', '');
  65. dC.css('max-height', (dC.children().outerHeight(true) + 'px'));
  66. setTimeout(function(){
  67. dC.css({'max-height':'0px','opacity':'0'});
  68. }, 10);
  69. r.timer = setTimeout(function(){
  70. dC.children().css('display', 'none');
  71. delete r.timer;
  72. }, 510);
  73. }
  74. },
  75. r: function(){
  76. $('.collapse_btn button[onclick^="t"]').each(function(i, b){
  77. b = $(b);
  78. b.attr('onclick', b.attr('onclick').replace(/^t.+,"/, 'commonui.reCollapseButton.f(event,"'));
  79. b.css({width:'1.2em', height:'1.2em', padding:'0', outline:'none', 'font-family':'Serif', 'line-height':'1.1em'});
  80. });
  81. },
  82. mo: {
  83. body : new MutationObserver(function(){
  84. r.r();
  85. })
  86. }
  87. };
  88.  
  89. r.r();
  90.  
  91. r.mo.body.observe($('body')[0], {
  92. childList: true,
  93. subtree: true,
  94. });
  95.  
  96. }
  97.  
  98. (function check(){
  99. try{
  100. init(commonui.userScriptLoader.$);
  101. }
  102. catch(e){
  103. setTimeout(check, 50);
  104. }
  105. })();
  106.  
  107. })();
  108.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址