// ==UserScript== // @name NGA Pins // @namespace https://greasyfork.org/zh-CN/scripts/36246-nga-pins // @version 0.0.4.20171211 // @icon http://bbs.nga.cn/favicon.ico // @description NGA Pins 可将顶部菜单、导航栏、页码栏固定在页面顶部,亦可通过设置取消其中某项;主帖内容较长时将作者信息固定在主帖左侧(不包含回复) // @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 // @downloadURL none // ==/UserScript== //发布地址:http://bbs.ngacn.cc/read.php?tid=13033636 (function(){ commonui.pins = {}; var pins = commonui.pins; function testStorage(s){ if(!!s){ try{ s.testkey = 'testvalue'; s.removeItem('testkey'); return true; } catch(e){ return false; } } else return false; } function init(){ let args = {}; if(localStorage.pins) args = JSON.parse(localStorage.pins); else{ args = {a: 56, b: 42, c: 43}; localStorage.pins = JSON.stringify(args); } __SETTING.pins = function(){ this.o = commonui.createCommmonWindow(); this.o._.addContent(null); var $ = window._$; this.o._.addTitle('Pins 设置'); let update = function(t){ if(t.checked) pins.args[t.name] = parseInt(t.value); else pins.args[t.name] = 0; localStorage.pins = JSON.stringify(pins.args); pins.update(); }, z = [['a', '56', '顶部菜单'], ['b','42', '导航栏'], ['c','43', '页码栏']]; for(let i = 0; i < z.length; i++){ let k = $('/input').$0('type','checkbox','checked',0,'name',z[i][0],'value',z[i][1])._.on('click', function(e){update(e.target);}); this.o._.addContent( k, z[i][2], $('/br') ); if(pins.args[z[i][0]]) k._.attr('checked', 1); } this.o._.show(); }; commonui.mainMenu.data[401] = {innerHTML: 'Pins 设置', on: {event: 'click', func: function(){__SETTING.pins();}}, parent: 18}; commonui.mainMenu.data[18].subKeys.push(401); return args; } pins.update = function(){ var $Q = jQuery.noConflict(), args = pins.args, hA = args.a + 8, hB = args.b && args.b + 8, hC = args.c && args.c + 8, a = $Q('#mainmenu'), b = $Q('#m_nav'), c = $Q('#m_pbtntop'), t = $Q('#posterinfo0').closest('td'), h = c.length && c.offset().top - hA - hB || b.offset().top - hA, z = [[a, 'pinsTopBar'], [b, 'pinsNavBar'], [c, 'pinsPageBar'], [t, 'pinsAuthorInfo']], newDiv = function(i){ return $Q('
').append(z[i][0].children()).appendTo(z[i][0]); }; //还原默认 for(let i = 0; i < z.length; i++){ if($Q('#' + z[i][1]).length){ $Q('#' + z[i][1]).contents().unwrap(); z[i][0].find('img.avatar').css({'margin-left':''}); } } $Q(window).unbind('.pins'); //顶部菜单 if(args.a){ let d = newDiv(0); d.css({'height':a.css('height'), 'width':'100%', 'overflow':'hidden', 'position':'fixed', 'top':'0px', 'z-index':'3', 'opacity':'0.95'}); $Q(window).bind('scroll.pins', function(){ if($Q(window).scrollTop() > $Q('#custombg').height()) d.css({'border-bottom':'1px solid #' + __COLOR.shadow1.replace(/;.+;/,'').replace(/^.+#/,'')}); else d.css({'border-bottom':''}); }); } //导航栏 if(args.b){ let d = newDiv(1); b.css({'height':b.css('height')}); b.find('.bbsinfo').prependTo(b); $Q(window).bind('scroll.pins', function(){ if($Q(window).scrollTop() > h) d.css({'position':'fixed', 'top':hA + 'px', 'z-index':'3', 'opacity':'0.95'}); else d.css({'position':'', 'top':'', 'z-index':'', 'opacity':''}); }); } //页码栏 if(args.c){ let d = newDiv(2); c.css({'height':c.css('height')}); c.find('tbody').css({'pointer-events':'auto'}); $Q(window).bind('scroll.pins', function(){ if($Q(window).scrollTop() > h) d.css({'width':'calc(100% - 20px)', 'position':'fixed', 'top':(hA + hB) + 'px', 'z-index':'2', 'opacity':'0.95', 'pointer-events':'none'}); else d.css({'width':'', 'position':'', 'top':'', 'z-index':'', 'opacity':''}); }); } //作者信息 if($Q('#posterinfo0').length && $Q('#posterinfo0').closest('td').outerHeight() > 600){ t.css({'min-width':'197px'}); let d = newDiv(3), h1 = hA + hB + hC + 6, h2 = d.offset().top - h1, w = function(){ d.css('width', t.css('width')); d.find('img.avatar').css({'margin-left':d.width() % 2 + 'px'}); }; $Q(window).bind('click.pins', function(){setTimeout(function(){w();}, 5);}); $Q(window).bind('transitionend.pins', function(){setTimeout(function(){w();}, 5);}); $Q(window).bind('resize.pins', function(){w();}); $Q(window).bind('scroll.pins', function(){ if($Q(window).scrollTop() > h2 && $Q(window).scrollTop() < t.height() - d.height() + h2){ d.css({'width':t.css('width'), 'position':'fixed', 'top':h1 + 'px'}); d.find('img.avatar').css({'margin-left':d.width() % 2 + 'px'}); } else if($Q(window).scrollTop() >= t.height() - d.height() + h2){ d.css({'width':t.css('width'), 'position':'fixed', 'top':(h1 - $Q(window).scrollTop() + t.height() - d.height() + h2) + 'px'}); d.find('img.avatar').css({'margin-left':d.width() % 2 + 'px'}); } else{ d.css({'width':'', 'position':'', 'top':''}); d.find('img.avatar').css({'margin-left':''}); } }); } $Q(window).triggerHandler('scroll.pins'); }; pins.args = !testStorage(window.localStorage) ? {a: 56, b: 42, c: 43} : init(); pins.update(); })();