Greasy Fork

Greasy Fork is available in English.

新标签页打开3dm论坛帖子

新标签页打开3dm论坛帖子 /change the way to open each result from "current tab" to "new tab"

当前为 2019-04-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         新标签页打开3dm论坛帖子
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  新标签页打开3dm论坛帖子 /change the way to open each result from "current tab" to "new tab"
// @author       MWY 3376766578
// @match        *://bbs.3dmgame.com/forum*.html
// @icon         https://www.3dmgame.com/index/images/logo_xiaoniao.png
// @grant        none
// ==/UserScript==



(function() {
    'use strict';
    function getList(){
       return document.getElementById('threadlisttableid').getElementsByClassName('s xst');
    }
    var as = getList();
    function modfiyA(as){
            for(var i=0;i<=as.length-1;i++){
                //console.log("第"+i+"次循环");
                //console.log(as[i]);
                as[i].onclick = null;
                as[i].target = '_blank';
            };
    }
    modfiyA(as);
    var totals = as.length;
    function checkList(){
        var c = getList();
        if(totals != c.length){
            console.log("刷新了,快看看数据吧!!!!!!!!");
            modfiyA(as);
            totals = c.length;
        }else{
            console.log("无数据变化");
        }
    }
    //--------------------------------------------------------------------------分割线--------------------------------------------------------------------------
    //下面代码是点击事件 下一页的 Ajax代码 。我在最后一句 加了 checkList()。 就是为了下一页数据加载完毕后 再次更改target
    var autopbn = $('autopbn');
    var nextpageurl = autopbn.getAttribute('rel').valueOf();
    var curpage = parseInt(autopbn.getAttribute('curpage').valueOf());
    var totalpage = parseInt(autopbn.getAttribute('totalpage').valueOf());
    var picstyle = parseInt(autopbn.getAttribute('picstyle').valueOf());
    var forumdefstyle = parseInt(autopbn.getAttribute('forumdefstyle').valueOf());
    picstyle = picstyle && !forumdefstyle;
    var autopagenum = 0;
    var maxpage = (curpage + autopagenum) > totalpage ? totalpage: (curpage + autopagenum);
    var loadstatus = 0;
    autopbn.onclick = function() {
        var oldloadstatus = loadstatus;
        loadstatus = 2;
        autopbn.innerHTML = '正在加载, 请稍后...';
        getnextpagecontent();
        loadstatus = oldloadstatus;
    };
    if (autopagenum > 0) {
        window.onscroll = function() {
            var curtop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
            if (curtop + document.documentElement.clientHeight + 500 >= document.documentElement.scrollHeight && !loadstatus) {
                loadstatus = 1;
                autopbn.innerHTML = '正在加载, 请稍后...';
                setTimeout(getnextpagecontent, 1000);
            }
        };
    }
    function getnextpagecontent() {
        if (curpage + 1 > totalpage) {
            window.onscroll = null;
            autopbn.style.display = 'none';
            return;
        }
        if (loadstatus != 2 && curpage + 1 > maxpage) {
            autopbn.innerHTML = '下一页 &raquo;';
            if (curpage + 1 > maxpage) {
                window.onscroll = null;
            }
            return;
        }
        curpage++;
        var url = nextpageurl + '&t=' + parseInt(( + new Date() / 1000) / (Math.random() * 1000));
        var x = new Ajax('HTML');
        x.get(url,
        function(s) {
            s = s.replace(/\n|\r/g, '');
            if (s.indexOf("id=\"autopbn\"") == -1) {
                $("autopbn").style.display = "none";
                window.onscroll = null;
            }
            if (!picstyle) {
                var tableobj = $('threadlisttableid');
                var nexts = s.match(/\<tbody id="normalthread_(\d+)"\>(.+?)\<\/tbody>/g);
                for (i in nexts) {
                    if (i == 'index' || i == 'lastIndex') {
                        continue;
                    }
                    var insertid = nexts[i].match(/<tbody id="normalthread_(\d+)"\>/);
                    if (!$('normalthread_' + insertid[1])) {
                        var newbody = document.createElement('tbody');
                        tableobj.appendChild(newbody);
                        var div = document.createElement('div');
                        div.innerHTML = '<table>' + nexts[i] + '</table>';
                        tableobj.replaceChild(div.childNodes[0].childNodes[0], tableobj.lastChild);
                    }
                }
            } else {
                var nexts2 = s.match(/\<li style="width:\d+px;" id="picstylethread_(\d+)"\>(.+?)\<\/li\>/g);
                for (i in nexts2) {
                    var insertid2 = nexts2[i].match(/id="picstylethread_(\d+)"\>/);
                    if (!$('picstylethread_' + insertid2[1])) {
                        $('threadlist_picstyle').innerHTML += nexts2[i];
                    }
                }
            }
            var pageinfo = s.match(/\<span id="fd_page_bottom"\>(.+?)\<\/span\>/);
            nextpageurl = nextpageurl.replace(/&page=\d+/, '&page=' + (curpage + 1));
            $('fd_page_bottom').innerHTML = pageinfo[1];
            if (curpage + 1 > totalpage) {
                autopbn.style.display = 'none';
            } else {
                autopbn.innerHTML = '下一页 &raquo;';
            }
            loadstatus = 0;
            checkList();
        });
    }
    //--------------------------------------------------------------------------分割线--------------------------------------------------------------------------
    // Your code here...
})();