Greasy Fork is available in English.

NGA Auto Pager V2

NGA自动翻页插件

// ==UserScript==
// @name        NGA Auto Pager V2
// @version     2.34
// @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="#snackbar{visibility:hidden;padding:12px;right:50px;bottom:30px;background-color:#333;color:#fff;text-align:center;border-radius:6px;position:fixed}#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("a");n.setAttribute("id","quick_reply"),n.setAttribute("href","#"),n.innerText="回";const i=document.createElement("a");i.setAttribute("id","next_post"),i.setAttribute("href","#");const a=document.createElement("div");a.setAttribute("id","pager_bar");const r=document.createElement("style");r.innerHTML='#pager_bar{display:flex;position:fixed;right:32px;bottom:72px;justify-content:space-evenly}#pager_bar a{margin-left:1px;visibility:hidden;background-color:#333;color:#fff;text-align:center;border-radius:6px;padding:8px;width:16px;height:16px;text-decoration:none;user-select:none}#pager_bar a:hover{color:#FFF;opacity:0.8}#pager_bar .show{visibility:visible}#btt{background:url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="16px" height="16px" viewBox="0 0 16 16"><polygon fill="#FFF" 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}#next_post{background:url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="16px" height="16px" viewBox="0 0 16 16"><polygon fill="#FFF" points="8,13.2 16,5.3 13.6,2.9 8.1,8.4 2.5,2.8 0,5.3 "/></svg>\') center 50% no-repeat #333}.fast_reply{position:fixed;left:33vw;top:25vh;background:#fff0cd;box-shadow:0 0 16px #403c33;border-radius:6px}',a.appendChild(i),a.appendChild(n),a.appendChild(o),document.body.appendChild(r),document.body.appendChild(a);const c=e=>{t.innerHTML=e,t.className="show",setTimeout(()=>{t.className=""},3e3)},s=$("fast_post_c"),l=document.querySelector("#fast_post_c a.uitxt1"),d=document.querySelector("#fast_post_c .row1 .c2 input"),u=document.querySelector("#fast_post_c .row1 .c2 textarea");if(null!=l){const e=l.cloneNode(!0);n.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",t=>{t.preventDefault(),commonui.newPost(e,postfunc.__REPLY_BLANK,window.__CURRENT_F_BIT,window.__CURRENT_FID,window.__CURRENT_TID,0,null,d.value,u.value),n.click(),c("正在回复")})}else document.querySelector("a.rep.uitxt1")&&n.setAttribute("href",document.querySelector("a.rep.uitxt1").href);const m=3e3,f=Math.round(($("topicrows")||$("m_posts")).getBoundingClientRect().top+window.scrollY);let b=!1,_=!1,w=2,g=0,h=document.querySelectorAll(".postbox"),x=1,y=!1,v=!1,E=window.pageYOffset|window.document.scrollTop;for(p of h)document.documentElement.scrollTop>p.getBoundingClientRect().top+window.scrollY&&g++;"undefined"!=typeof __PAGE&&(x=__PAGE[2],w=0===__PAGE[0].indexOf("/read")?2:1026,b=null!==document.querySelector("a.uitxt1[title=加载下一页]")),2===w&&(v=!0,i.className="show"),o.addEventListener("click",e=>{e.preventDefault(),window.scrollTo({top:f,left:0,behavior:"smooth"}),y=!0}),i.addEventListener("click",e=>{e.preventDefault(),window.scrollTo({top:h[g].getBoundingClientRect().top+window.scrollY,left:0,behavior:"smooth"}),h.length>g+1&&g++});const A=new FileReader,N=()=>{const e=pr(A.result,w),t=e[1].match(/\s*<tbody/)?_$("/table"):_$("/span"),o=document.getElementsByName("pageball"),n=$("m_posts_c")||$("topicrows");eval(e[0]),t.innerHTML=e[1],t.childNodes.forEach(e=>{(1024&w&&"TBODY"==e.nodeName||"forumbox postbox"==e.className)&&n.insertBefore(e,null)}),e[2].forEach(e=>eval(e)),__PAGE[2]++,commonui.pageBtn(o[0],{0:__PAGE[0],1:__PAGE[1],2:x,3:__PAGE[3]},20),commonui.pageBtn(o[1],{0:__PAGE[0],1:__PAGE[1],2:__PAGE[2],3:__PAGE[3]},10),_=!1,h=document.querySelectorAll(".postbox")};A.addEventListener("loadend",N);const k=e=>()=>{try{e()}catch(e){console.error("NGA Autopager V2",e)}},T=async()=>{const e=window.pageYOffset||window.document.scrollTop;if(v&&(e>E?e>h[g].getBoundingClientRect().top+window.scrollY&&h.length>g+1&&g++:g>0&&e<h[g-1].getBoundingClientRect().top+window.scrollY&&g>1&&g--,E=e),y&&Math.abs(e-f)<2&&(g=1,y=!1),e<1e3?(o.className="",v&&(n.className="",0!==s.className.length&&n.click())):(o.className="show",v&&(n.className="show")),navigator.onLine&&b&&!_&&document.documentElement.scrollHeight-e<m){if(_=!0,null!==document.querySelector("a.uitxt1[title=加载下一页]")){c(`正在加载第${__PAGE[2]+1}页`);try{const e=await fetch(`${__PAGE[0]}&page=${__PAGE[2]+1}`);A.readAsText(await e.blob(),"gbk")}catch(e){console.error("NGA Autopager V2",e),c("加载错误")}}else b=!1}};window.addEventListener("scroll",k(T));