Greasy Fork is available in English.

NGA Pins

NGA Pins 可将顶部菜单、导航栏、页码栏固定在窗口顶部,亦可通过设置取消其中某项;主帖内容较长时将作者信息固定在主帖左侧(不包含回复)

  1. // ==UserScript==
  2. // @name NGA Pins
  3. // @namespace https://greasyfork.org/zh-CN/scripts/36246-nga-pins
  4. // @version 0.1.4.20200528
  5. // @icon http://bbs.nga.cn/favicon.ico
  6. // @description NGA Pins 可将顶部菜单、导航栏、页码栏固定在窗口顶部,亦可通过设置取消其中某项;主帖内容较长时将作者信息固定在主帖左侧(不包含回复)
  7. // @author AgLandy
  8. // @include /^https?:\/\/(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/
  9. // @grant none
  10. // @require https://greasyfork.org/scripts/39014-nga-user-script-loader/code/NGA%20User%20Script%20Loader.js
  11. // @license MIT License
  12. // ==/UserScript==
  13.  
  14. //发布地址:http://bbs.ngacn.cc/read.php?tid=13033636
  15.  
  16. (function(){
  17.  
  18. function init(usl){
  19.  
  20. let $ = usl.$,
  21. p = commonui.pins = {
  22. init: function(){
  23. let args = {};
  24. if(localStorage.pins)
  25. args = JSON.parse(localStorage.pins);
  26. else{
  27. args = {a: 56, b: 42, c: 43};
  28. localStorage.pins = JSON.stringify(args);
  29. }
  30. return args;
  31. },
  32. f: function(){
  33.  
  34. let args = p.args,
  35. hA = args.a + 8,
  36. hB = args.b && args.b + 8,
  37. hC = args.c && args.c + 8,
  38. a = $('#mainmenu'),
  39. b = $('#m_nav'),
  40. c = $('#m_pbtntop'),
  41. t = $('#posterinfo0').closest('td'),
  42. h = c[0] && c.offset().top - hA - hB || b.offset().top - hA,
  43. o = $('body > #pinsPins')[0] ? $('body > #pinsPins') : $('<div id="pinsPins" style="margin:0px 10px" />').appendTo('body'), //为导航栏和页码栏创建外部div
  44. z = [[a, 'pinsTopBar'], [b, 'pinsNavBar'], [c, 'pinsPageBar'], [t, 'pinsAuthorInfo']],
  45. newDiv = function(i){
  46. return $('<div id="' + z[i][1] + '" />').append(z[i][0].children()).appendTo(z[i][0]);
  47. };
  48.  
  49. //还原默认
  50. for(let i = 0; i < z.length; i++){
  51. if($('#' + z[i][1])[0])
  52. if(i % 3 != 0 && o.find('#' + z[i][1])[0] && z[i][0].children()[0])
  53. o.find('#' + z[i][1]).remove();
  54. else
  55. $('#' + z[i][1]).appendTo(z[i][0]).contents().unwrap();
  56. }
  57. $(window).unbind('.pins');
  58.  
  59. //顶部菜单
  60. if(args.a){
  61. let d = newDiv(0);
  62. d.css({'height':a.css('height'), 'width':'100%', 'overflow':'hidden', 'position':'fixed', 'top':'0px', 'z-index':'3', 'opacity':'0.95'});
  63. $(window).bind('scroll.pins', function(){
  64. if($(window).scrollTop() > $('#custombg').height())
  65. d.css({'border-bottom':'1px solid #' + __COLOR.shadow1.replace(/;.+;/,'').replace(/^.+#/,'')});
  66. else
  67. d.css({'border-bottom':''});
  68. });
  69. }
  70.  
  71. //导航栏
  72. if(args.b){
  73. let d = newDiv(1);
  74. b.css({'height':b.css('height')});
  75. b.find('.bbsinfo').prependTo(b);
  76. $(window).bind('scroll.pins', function(){
  77. if($(window).scrollTop() > h)
  78. d.css({'position':'fixed', 'top':hA + 'px', 'z-index':'3', 'opacity':'0.95'}).appendTo(o);
  79. else
  80. d.css({'position':'', 'top':'', 'z-index':'', 'opacity':''}).appendTo(b);
  81. });
  82. }
  83.  
  84. //页码栏
  85. if(args.c){
  86. let d = newDiv(2);
  87. c.css({'height':c.css('height')});
  88. $(window).bind('scroll.pins', function(){
  89. if($(window).scrollTop() > h)
  90. d.css({'width':'calc(100% - 20px)', 'position':'fixed', 'top':(hA + hB) + 'px', 'z-index':'2', 'opacity':'0.95', 'pointer-events':'none'}).appendTo(o);
  91. else
  92. d.css({'width':'', 'position':'', 'top':'', 'z-index':'', 'opacity':'', 'pointer-events':''}).appendTo(c);
  93. });
  94. }
  95.  
  96. //作者信息
  97. if($('#posterinfo0')[0] && $('#posterinfo0').closest('td').outerHeight() > 600){
  98. t.css({'min-width':'197px'});
  99. let d = newDiv(3),
  100. h1 = hA + hB + hC + 6,
  101. h2 = d.offset().top - h1,
  102. w = function(){
  103. d.css('width', t.css('width'));
  104. };
  105. if(/firefox/.test(navigator.userAgent.toLowerCase())){
  106. $('.postcontent').bind('click.pins', function(){setTimeout(w,5);});
  107. $(window).bind('transitionend.pins', function(){setTimeout(w,5);});
  108. }
  109. else{
  110. let mo = new MutationObserver(w);
  111. mo.observe($('#posterinfo0').closest('table')[0], {
  112. childList: true,
  113. subtree: true,
  114. attributes: true
  115. });
  116. }
  117. $(window).bind('resize.pins', w);
  118. $(window).bind('scroll.pins', function(){
  119. if($(window).scrollTop() > h2 && $(window).scrollTop() < t.height() - d.height() + h2)
  120. d.css({'width':t.css('width'), 'position':'fixed', 'top':h1 + 'px'});
  121. else if($(window).scrollTop() >= t.height() - d.height() + h2)
  122. d.css({'width':t.css('width'), 'position':'fixed', 'top':(h1 - $(window).scrollTop() + t.height() - d.height() + h2) + 'px'});
  123. else
  124. d.css({'width':'', 'position':'', 'top':''});
  125. });
  126. }
  127.  
  128. $(window).triggerHandler('scroll.pins');
  129.  
  130. }
  131. };
  132.  
  133. commonui.mainMenu.data[401] = {innerHTML: 'Pins 设置', on: {event: 'click', func: function(e){
  134. let o = __SETTING.o = commonui.createadminwindow(),
  135. z = [['a', '56', '顶部菜单'], ['b','42', '导航栏'], ['c','43', '页码栏']];
  136. o._.addContent(null);
  137. o._.addTitle('Pins 设置');
  138. $.each(z, function(i, zi){
  139. let k = _$('/input').$0('type','checkbox','checked',0,'name',zi[0],'value',zi[1])._.on('click', function(){
  140. p.args[this.name] = this.checked ? parseInt(this.value) : 0;
  141. localStorage.pins = JSON.stringify(p.args);
  142. p.f();
  143. });
  144. o._.addContent(
  145. k,
  146. zi[2],
  147. _$('/br')
  148. );
  149. if(p.args[zi[0]])
  150. k._.attr('checked', 1);
  151. });
  152. o._.show(e);
  153. }}, parent: 18};
  154. commonui.mainMenu.data[18].subKeys.push(401);
  155.  
  156. $('div#mainmenu input[placeholder$="搜索"]')[0]._on = function(){
  157. var o = this.__w;
  158. if(!o){
  159. o = (this.__w = commonui.createCommmonWindow(2));
  160. o._.addContent(
  161. _$('/span')._.add(
  162. commonui.uniSearchInput(this)
  163. )
  164. );
  165. o.firstChild.lastChild.style.backgroundColor = __COLOR.bg4;
  166. with(o.style){
  167. left = top = '0';
  168. visibility = 'hidden';
  169. display = 'block';
  170. boxShadow = 'none';
  171. borderTop = 'none';
  172. marginTop = '-1px';
  173. }
  174. document.body.appendChild(o);
  175. o._b = o.getBoundingClientRect();
  176. var se = this;
  177. commonui.aE(document.body, 'click', function(e){
  178. var h = e.target || e.srcElement;
  179. for(var i = 0; i < 7; i++){
  180. if(h == o || h == se.parentNode.parentNode)
  181. return;
  182. h = h.parentNode;
  183. if(!h)
  184. break;
  185. }
  186. o._.hide();
  187. });
  188. }
  189. if(o.style.display == 'none' || o.style.visibility == 'hidden'){
  190. var p = this.parentNode.parentNode.getBoundingClientRect();
  191. if(commonui.pins.args.a != 0)
  192. $(o).css({left: p.left + p.width - o._b.width + 'px', top: p.top + p.height + 'px', position: 'fixed', visibility: 'inherit'}).fadeIn('fast');
  193. else
  194. o._.css('position','')._.show(p.left + p.width - o._b.width, p.top + p.height);
  195. }
  196. }; //default.js commonui.mainMenuItems[162]
  197.  
  198. $('<style type="text/css" />').html(' #pinsPins tbody {pointer-events:auto;} ').appendTo('head');
  199.  
  200. p.args = usl.lS ? p.init() : {a: 56, b: 42, c: 43};
  201.  
  202. p.f();
  203.  
  204. if(!usl.userScriptData.pins)
  205. usl.userScriptData.pins = p.f;
  206.  
  207. }
  208.  
  209. (function check(){
  210. try{
  211. if(commonui.userScriptLoader.$)
  212. init(commonui.userScriptLoader);
  213. else
  214. setTimeout(check, 5);
  215. }
  216. catch(e){
  217. setTimeout(check, 50);
  218. }
  219. })();
  220.  
  221. })();
  222.  
  223.  
  224.  
  225.  
  226.  
  227.