您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
NGA Pins 可将顶部菜单、导航栏、页码栏固定在窗口顶部,亦可通过设置取消其中某项;主帖内容较长时将作者信息固定在主帖左侧(不包含回复)
当前为
- // ==UserScript==
- // @name NGA Pins
- // @namespace https://greasyfork.org/zh-CN/scripts/36246-nga-pins
- // @version 0.0.9.20180215
- // @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
- // @license MIT License
- // ==/UserScript==
- //发布地址:http://bbs.ngacn.cc/read.php?tid=13033636
- 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)
- return;
- 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;
- }
- $Q('<style type="text/css" />').html(' #m_pbtntop tbody {pointer-events:auto;} ').appendTo('head');
- pins.update = function(){
- let 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('<div id="' + z[i][1] + '" />').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();
- }
- $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')});
- $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'));
- };
- if(/firefox/.test(navigator.userAgent.toLowerCase())){
- $Q('.postcontent').bind('click.pins', function(){setTimeout(w,5);});
- $Q(window).bind('transitionend.pins', function(){setTimeout(w,5);});
- }
- else{
- let mo = new MutationObserver(w);
- mo.observe($Q('#posterinfo0').closest('table')[0], {
- childList: true,
- subtree: true,
- attributes: true
- });
- }
- $Q(window).bind('resize.pins', 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'});
- 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'});
- else
- d.css({'width':'', 'position':'', 'top':''});
- });
- }
- $Q(window).triggerHandler('scroll.pins');
- };
- pins.args = !testStorage(window.localStorage) ? {a: 56, b: 42, c: 43} : init();
- pins.update();
- }