Greasy Fork

Greasy Fork is available in English.

NGA Pins

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

当前为 2018-03-14 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         NGA Pins
// @namespace    http://greasyfork.icu/zh-CN/scripts/36246-nga-pins
// @version      0.1.1.20180315
// @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://greasyfork.icu/scripts/39014-nga-user-script-loader/code/NGA%20User%20Script%20Loader.js
// @license      MIT License
// ==/UserScript==

//发布地址:http://bbs.ngacn.cc/read.php?tid=13033636

(function(){

    function init(usl){

        let $ = usl.$,
            p = commonui.pins = {
                init: function(){
                    let args = {};
                    if(localStorage.pins)
                        args = JSON.parse(localStorage.pins);
                    else{
                        args = {a: 56, b: 42, c: 43};
                        localStorage.pins = JSON.stringify(args);
                    }
                    return args;
                },
                f: function(){

                    let args = p.args,
                        hA = args.a + 8,
                        hB = args.b && args.b + 8,
                        hC = args.c && args.c + 8,
                        a = $('#mainmenu'),
                        b = $('#m_nav'),
                        c = $('#m_pbtntop'),
                        t = $('#posterinfo0').closest('td'),
                        h = c[0] && c.offset().top - hA - hB || b.offset().top - hA,
                        o = $('body > #pinsPins')[0] ? $('body > #pinsPins') : $('<div id="pinsPins" style="margin:0px 10px" />').appendTo('body'),  //为导航栏创建外部div
                        z = [[a, 'pinsTopBar'], [b, 'pinsNavBar'], [c, 'pinsPageBar'], [t, 'pinsAuthorInfo']],
                        newDiv = function(i){
                            return $('<div id="' + z[i][1] + '" />').append(z[i][0].children()).appendTo(z[i][0]);
                        };

                    //还原默认
                    for(let i = 0; i < z.length; i++){
                        if($('#' + z[i][1])[0])
                            $('#' + z[i][1]).appendTo(z[i][0]).contents().unwrap();
                    }
                    $(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'});
                        $(window).bind('scroll.pins', function(){
                            if($(window).scrollTop() > $('#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);
                        $(window).bind('scroll.pins', function(){
                            if($(window).scrollTop() > h)
                                d.css({'position':'fixed', 'top':hA + 'px', 'z-index':'3', 'opacity':'0.95'}).appendTo(o);
                            else
                                d.css({'position':'', 'top':'', 'z-index':'', 'opacity':''}).appendTo(b);
                        });
                    }

                    //页码栏
                    if(args.c){
                        let d = newDiv(2);
                        c.css({'height':c.css('height')});
                        $(window).bind('scroll.pins', function(){
                            if($(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($('#posterinfo0')[0] && $('#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())){
                            $('.postcontent').bind('click.pins', function(){setTimeout(w,5);});
                            $(window).bind('transitionend.pins', function(){setTimeout(w,5);});
                        }
                        else{
                            let mo = new MutationObserver(w);
                            mo.observe($('#posterinfo0').closest('table')[0], {
                                childList: true,
                                subtree: true,
                                attributes: true
                            });
                        }
                        $(window).bind('resize.pins', w);
                        $(window).bind('scroll.pins', function(){
                            if($(window).scrollTop() > h2 && $(window).scrollTop() < t.height() - d.height() + h2)
                                d.css({'width':t.css('width'), 'position':'fixed', 'top':h1 + 'px'});
                            else if($(window).scrollTop() >= t.height() - d.height() + h2)
                                d.css({'width':t.css('width'), 'position':'fixed', 'top':(h1 - $(window).scrollTop() + t.height() - d.height() + h2) + 'px'});
                            else
                                d.css({'width':'', 'position':'', 'top':''});
                        });
                    }

                    $(window).triggerHandler('scroll.pins');

                }
            };

        commonui.mainMenu.data[401] = {innerHTML: 'Pins 设置', on: {event: 'click', func: function(e){
            let o = __SETTING.o = commonui.createadminwindow(),
                z = [['a', '56', '顶部菜单'], ['b','42', '导航栏'], ['c','43', '页码栏']];
            o._.addContent(null);
            o._.addTitle('Pins 设置');
            $.each(z, function(i, zi){
                let k = _$('/input').$0('type','checkbox','checked',0,'name',zi[0],'value',zi[1])._.on('click', function(){
                    p.args[this.name] = this.checked ? parseInt(this.value) : 0;
                    localStorage.pins = JSON.stringify(p.args);
                    p.f();
                });
                o._.addContent(
                    k,
                    zi[2],
                    _$('/br')
                );
                if(p.args[zi[0]])
                    k._.attr('checked', 1);
            });
            o._.show(e);
        }}, parent: 18};
        commonui.mainMenu.data[18].subKeys.push(401);

        $('<style type="text/css" />').html(' #m_pbtntop tbody {pointer-events:auto;} ').appendTo('head');

        p.args = usl.lS ? p.init() : {a: 56, b: 42, c: 43};

        p.f();

        if(!usl.userScriptData.pins)
            usl.userScriptData.pins = p.f;

    }

    (function check(){
        try{
            if(commonui.userScriptLoader.$)
                init(commonui.userScriptLoader);
            else
                setTimeout(check, 5);
        }
        catch(e){
            setTimeout(check, 50);
        }
    })();

})();