Greasy Fork

NGA Auto Pager V2

NGA自动翻页插件

目前为 2018-10-04 提交的版本。查看 最新版本

// ==UserScript==
// @name        NGA Auto Pager V2
// @version     2.23
// @description NGA自动翻页插件
// @match *://bbs.nga.cn/read.php*
// @match *://bbs.nga.cn/thread.php*
// @match *://bbs.nga.cn/wow*
// @match *://bbs.nga.cn/it*
// @match *://bbs.nga.cn/auto*
// @match *://bbs.nga.cn/ink*
// @match *://bbs.nga.cn/ng2*
// @match *://bbs.nga.cn/play*
// @match *://bbs.nga.cn/tvgame*
// @match *://bbs.nga.cn/wa2*
// @match *://bbs.nga.cn/ccq*
// @match *://bbs.nga.cn/gw2*
// @match *://bbs.nga.cn/bns*
// @match *://bbs.nga.cn/heroes*
// @match *://bbs.nga.cn/lol*
// @match *://bbs.nga.cn/hs*
// @match *://bbs.nga.cn/wot*
// @match *://bbs.nga.cn/jx3*
// @match *://bbs.nga.cn/coc*
// @match *://bbs.nga.cn/pad*
// @match *://bbs.nga.cn/d3*
// @match *://bbs.nga.cn/dota*
// @match *://bbs.nga.cn/wt*
// @match *://bbs.nga.cn/ff14*
// @match *://bbs.nga.cn/poi*
// @match *://bbs.nga.cn/gta*
// @match *://bbs.nga.cn/sc*
// @match *://bbs.nga.cn/fn*
// @match *://bbs.nga.cn/ow*
// @match *://bbs.nga.cn/cr*
// @match *://bbs.nga.cn/king*
// @match *://nga.178.com/read.php*
// @match *://nga.178.com/thread.php*
// @match *://nga.178.com/wow*
// @match *://nga.178.com/it*
// @match *://nga.178.com/auto*
// @match *://nga.178.com/ink*
// @match *://nga.178.com/ng2*
// @match *://nga.178.com/play*
// @match *://nga.178.com/tvgame*
// @match *://nga.178.com/wa2*
// @match *://nga.178.com/ccq*
// @match *://nga.178.com/gw2*
// @match *://nga.178.com/bns*
// @match *://nga.178.com/heroes*
// @match *://nga.178.com/lol*
// @match *://nga.178.com/hs*
// @match *://nga.178.com/wot*
// @match *://nga.178.com/jx3*
// @match *://nga.178.com/coc*
// @match *://nga.178.com/pad*
// @match *://nga.178.com/d3*
// @match *://nga.178.com/dota*
// @match *://nga.178.com/wt*
// @match *://nga.178.com/ff14*
// @match *://nga.178.com/poi*
// @match *://nga.178.com/gta*
// @match *://nga.178.com/sc*
// @match *://nga.178.com/fn*
// @match *://nga.178.com/ow*
// @match *://nga.178.com/cr*
// @match *://nga.178.com/king*
// @author      Sunness
// @namespace https://greasyfork.org/users/63731
// @license GPL-3.0-or-later
// ==/UserScript==

const e=document.createElement("style");e.innerHTML=".pager_style{background-color:#333;color:#fff;text-align:center;border-radius:6px;padding:8px;position:fixed}#snackbar{visibility:hidden;padding:12px;right:50px;bottom:30px}#snackbar.show{visibility:visible;-webkit-animation:fadein .5s,fadeout .5s 2.5s;animation:fadein .5s,fadeout .5s 2.5s}@-webkit-keyframes fadein{from{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@keyframes fadein{from{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@-webkit-keyframes fadeout{from{bottom:30px;opacity:1}to{bottom:0;opacity:0}}@keyframes fadeout{from{bottom:30px;opacity:1}to{bottom:0;opacity:0}}";const t=document.createElement("div");t.setAttribute("id","snackbar"),document.body.appendChild(e),document.body.appendChild(t);const o=document.createElement("a");o.setAttribute("id","btt"),o.setAttribute("href","#");const n=document.createElement("style");n.innerHTML='#btt{visibility:hidden;background:url(\'data:image/svg+xml;utf8,<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="16px" height="16px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve"><polygon fill="#FFFFFF" points="8,2.8 16,10.7 13.6,13.1 8.1,7.6 2.5,13.2 0,10.7 "/></svg>\') center 50% no-repeat #333;right:30px;bottom:72px;height:16px;width:16px}#btt.show{visibility:visible}',document.body.appendChild(n),document.body.appendChild(o);const i=document.createElement("a");i.setAttribute("id","quick_reply"),i.setAttribute("href","#"),i.innerText="回";const a=document.createElement("style");a.innerHTML="#quick_reply:hover{color:#FFF;}#quick_reply{visibility:hidden;text-decoration:none;user-select:none;right:63px;bottom:72px;height:16px;width:16px;font-size:12px;}#quick_reply.show{visibility:visible}.fast_reply{position:fixed;left:33vw;top:25vh;background:#FFF0CD;box-shadow:0 0 16px #403C33;border-radius:6px}",document.body.appendChild(a),document.body.appendChild(i);const s=$("fast_post_c"),l=document.querySelector("#fast_post_c a.uitxt1"),c=document.querySelector("#fast_post_c .row1 .c2 input"),r=document.querySelector("#fast_post_c .row1 .c2 textarea");if(null!=l){const e=l.cloneNode(!0);i.addEventListener("click",t=>{t.preventDefault(),0===s.className.length?(s.className="fast_reply",l.parentNode.replaceChild(e,l)):(e.parentNode.replaceChild(l,e),s.className="")}),e.addEventListener("click",o=>{o.preventDefault(),commonui.newPost(e,postfunc.__REPLY_BLANK,window.__CURRENT_F_BIT,window.__CURRENT_FID,window.__CURRENT_TID,0,null,c.value,r.value),i.click(),t.innerHTML="正在回复",t.className="show",setTimeout(()=>{t.className=""},3e3)})}else i.setAttribute("href",document.querySelector("a.rep.uitxt1").href);const d=3e3,p=Math.round(($("topicrows")||$("m_posts")).getBoundingClientRect().top+window.scrollY);let m=!1,u=!1,_=2,b=1;"undefined"!=typeof __PAGE&&(b=__PAGE[2],_=0===__PAGE[0].indexOf("/read")?2:1026,m=!0),o.addEventListener("click",e=>{e.preventDefault(),window.scrollTo({top:p,left:0,behavior:"smooth"})}),window.addEventListener("scroll",async()=>{if(document.documentElement.scrollTop<1e3?(o.className="pager_style",2===_&&null!=i&&(i.className="pager_style",0!==s.className.length&&i.click())):(o.className="pager_style show",2===_&&null!=i&&(i.className="pager_style show")),m&&!u&&document.documentElement.scrollHeight-document.documentElement.scrollTop<d){u=!0;const e=document.querySelector("a.uitxt1[title=加载下一页]");if(null!==e){t.innerHTML=`正在加载第${__PAGE[2]+1}页`,t.className="pager_style show",setTimeout(()=>{t.className="pager_style"},3e3);const e=await fetch(`${__PAGE[0]}&page=${__PAGE[2]+1}`,{credentials:"same-origin"}),o=new FileReader;o.addEventListener("loadend",()=>{const e=pr(o.result,_),t=e[1].match(/\s*<tbody/)?_$("/table"):_$("/span"),n=document.getElementsByName("pageball"),i=$("m_posts_c")||$("topicrows");eval(e[0]),t.innerHTML=e[1],t.childNodes.forEach(e=>{(1024&_&&"TBODY"==e.nodeName||"forumbox postbox"==e.className)&&i.insertBefore(e,null)}),e[2].forEach(e=>eval(e)),__PAGE[2]++,commonui.pageBtn(n[0],{0:__PAGE[0],1:__PAGE[1],2:b,3:__PAGE[3]},20),commonui.pageBtn(n[1],{0:__PAGE[0],1:__PAGE[1],2:__PAGE[2],3:__PAGE[3]},10),u=!1}),o.readAsText(await e.blob(),"gbk")}else m=!1}});