Greasy Fork

Greasy Fork is available in English.

NGA Subscribe Tool

NGA 订阅工具,在打开页面时检测关注的作者是否发布了新帖,若是则在进入版面时弹出提醒(在帖子内不提醒)

当前为 2018-02-24 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NGA Subscribe Tool
// @namespace    http://greasyfork.icu/zh-CN/scripts/38841-nga-subscribe-tool
// @version      0.0.4.20180224
// @icon         http://bbs.nga.cn/favicon.ico
// @description  NGA 订阅工具,在打开页面时检测关注的作者是否发布了新帖,若是则在进入版面时弹出提醒(在帖子内不提醒)
// @author       AgLandy
// @include      /^https?:\/\/(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/(thread\.php\?(f|st)id|read).+/
// @grant        none
// ==/UserScript==


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


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){

    setTimeout(function(){

        if(!window.commonui)
            return;

        let ls = (function testStorage(s){
            if(!!s){
                try{
                    s.testkey = 'testvalue';
                    s.removeItem('testkey');
                    return true;
                }
                catch(e){
                    return false;
                }
            }
            else
                return false;
        })(window.localStorage),
            init = function(){
                let data = {};
                if(localStorage.subscribeToolData)
                    data = JSON.parse(localStorage.subscribeToolData);
                else{
                    data = {'8143443':{'name':'奥妮酱', 'read':1}};
                    localStorage.subscribeToolData = JSON.stringify(data);
                }
                return data;
            },
            st = commonui.subscribeTool = {};

        st.cache = {};
        st.data = !ls ? {'8143443':{'name':'奥妮酱'}} : init();
        st.notifunc = function(ck){
            let noti = commonui.notification,
                go = function(){
                    for(let i = 0; i < ck.length; i++){
                        let t = st.cache[ck[i]],
                            s = commonui.cutstrbylen(t[2],19);
                        if(s.length < t[2].length)
                            s += '...';
                        $Q('<span><b style="color:blue">&#9632;</b> <span class="silver">' +
                           commonui.time2dis(ck[i]) +
                           ' <a class="b" target="_blank" href="/nuke.php?func=ucp&uid=' + t[1] + '">' +
                           t[0] +
                           '</a> 发布了主题 <nobr><a class="b" href="' + t[3] + '" title="' + t[2] + '" target="_blank">' +
                           s +
                           '</a></nobr><br></span></span>').prependTo('div.single_ttip2 div.div1:has(span.title:contains("提醒信息")) td:eq(0)');  //js_notification.js
                        st.data[t[1]].read = 1;
                        localStorage.subscribeToolData = JSON.stringify(st.data);
                    }
                    st.cache = {};
                };

            if(!noti.box)
                noti.createBox();
            if(noti.box.style.display != 'none')
                return go();
            if(!document.body)
                return window.setTimeout(function(){st.notifunc(ck);}, 3000);
            if(noti.box.parentNode != document.body)
                document.body.appendChild(noti.box);
            noti.box._.show(0,0);
            if(noti.box.offsetHeight > __NUKE.position.get().ch){
                if(noti.box.style.position != 'absolute')
                    noti.box.style.position = 'absolute';
                if(noti.timeout)
                    window.clearInterval(noti.timeout);
            }
            else{
                if(noti.box.style.position != 'fixed')
                    noti.box.style.position = 'fixed';
                if(window.__UA && __UA[0] == 1 && __UA[1] <= 6)
                    noti.timeout = window.setInterval(function(){commonui.notification.checkPos();}, 3000);
            }  //notification.js  commonui.notification.openBox

            go();
        };

        //检测是否有关注作者的新帖
        let n = 0;
        if(ls)
            $Q.each(st.data, function(k, v){
                if(v == null){
                    n++;
                    return;
                }  //取消关注的作者跳过检测
                if(commonui.postArg && commonui.postArg.data[0] && commonui.postArg.data[0].pAid == k && __CURRENT_TID > v.lastTid){
                    v.lastTid = __CURRENT_TID;
                    v.read = 1;
                    localStorage.subscribeToolData = JSON.stringify(st.data);
                    n++;
                    return;
                }  //若当前页为关注作者的新帖首页则不再提示该帖
                $Q.post('thread.php?order_by=postdatedesc&authorid=' + k, 'lite=xml', function(response){
                    let t = $Q(response).find('__T item:eq(0)'),
                        tid = parseInt(t.find('tid').text()),
                        postdate = parseInt(t.find('postdate').text()),
                        author = t.find('author').text(),
                        authorid = t.find('authorid').text(),
                        subject = t.find('subject').text(),
                        url = t.find('tpcurl').text();
                    if(tid > v.lastTid){
                        v.read = 0;
                        if(authorid != '0')
                            st.cache[postdate] = [author, authorid, subject, url];
                    }
                    else if(authorid != '0' && v.read == 0){
                        st.cache[postdate] = [author, authorid, subject, url];
                    }
                    v.lastTid = tid;
                    localStorage.subscribeToolData = JSON.stringify(st.data);
                    n++;
                });
            });

        //版面中显示关注作者头像
        if(/\/thread\.php\?(f|st)id.+$/.test(window.location.href)){

            let authors = $Q('a[href^="/nuke.php?func=ucp&uid="]');

            if(!authors[0])
                return;

            $Q.each(authors, function(i, author){

                let uid = author.href.replace(/\D/g, '');

                if(!st.data[uid])
                    return;

                $Q.post('nuke.php?__lib=ucp&__act=get&uid=' + uid, '__output=12', function(response){
                    if(!response.result.avatar)
                        return;
                    let a = commonui.selectAvatar(response.result.avatar, __CURRENT_UID),
                        td = author.parentNode,
                        rp = td.getClientRects()[0],
                        h = rp.bottom - rp.top,
                        d = _$('/div').$0(
                            'style', {
                                borderRight: '1px solid ' + __COLOR.bg0,
                                overflow: 'hidden',
                                width: h + 'px',
                                height: h + 'px',
                                cssFloat: 'left',
                                margin: '-6px 0 -6px -' + h + 'px'
                            },
                            _$('/img').$0(
                                'onload', function(){
                                    let r;
                                    if(this.height > this.width){
                                        r = h / this.width;
                                        this.width = h;
                                        this.height *= r;
                                        this.style.marginTop = (Math.abs(h - this.height) / 3 * -1) + 'px';
                                    }
                                    else{
                                        r = h / this.height;
                                        this.height = h;
                                        this.width *= r;
                                        this.style.marginLeft = (Math.abs(h - this.width) / 2 * -1) + 'px';
                                    }
                                    this.style.opacity = 0.7;
                                    this.style.display = '';
                                },
                                'style', {display:'none'},
                                'src', a
                            )
                        );
                    td.style.paddingLeft = h + 'px';
                    $Q(td).prepend(d);  //forum.js  commonui.loadThreadInfoSetAvatar
                });

            });

            //新帖提醒
            if(ls)
                (function check(){
                    if(st.check){
                        if(st.check > 20){
                            console.log('st.check : timeout');
                            delete st.check;
                            st.cache = {};
                            return;
                        }
                        else
                            st.check++;
                    }
                    else
                        st.check = 1;

                    if(n == Object.keys(st.data).length){
                        console.log('st.check : ' + st.check);
                        delete st.check;
                        let ck = Object.keys(st.cache);
                        if(ck[0])
                            if(commonui.notification)
                                st.notifunc(ck);
                            else
                                commonui.loadNotiScript(function(){
                                    st.notifunc(ck);
                                });
                    }
                    else
                        setTimeout(function(){
                            check();
                        },150);
                })();

        }

        //在帖子中为除自己以外的楼层添加关注按钮
        if(ls && $Q('a[name="uid"]')[0]){

            $Q.each($Q('a[name="uid"]'), function(i, uid){

                let a = $Q(uid),
                    u = a.text();

                if(u == __CURRENT_UID)
                    return;

                a.parent().css({'position':'relative'});
                let d = $Q('<span style="font:15px/16px Serif;vertical-align:bottom;margin-left:3px;color:#ff7800;cursor:pointer;display:none;" />').html(st.data[u] ? '♥' : '♡').click(function(){
                    d.html(st.data[u] ? '♡' : '♥');
                    st.data[u] = st.data[u] ? null : {'name':commonui.posterInfo.uI.users[u].username, 'read':1};
                    localStorage.subscribeToolData = JSON.stringify(st.data);
                }).insertAfter(a);
                a.closest('td').mouseenter(function(){d.fadeIn();}).mouseleave(function(){d.fadeOut();});

            });

        }

    },100);

}