启用NGA自动向后加载

在进入NGA帖子时自动轮询最后一页的内容,并去重后添加到页面末尾

目前为 2019-08-03 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 启用NGA自动向后加载
  3. // @namespace https://yuyuyzl.github.io/
  4. // @version 0.2
  5. // @description 在进入NGA帖子时自动轮询最后一页的内容,并去重后添加到页面末尾
  6. // @author yuyuyzl
  7. // @require https://code.jquery.com/jquery-3.4.0.min.js
  8. // @match http://nga.178.com/read.php?tid=*&page=*
  9. // @match http://bbs.nga.cn/read.php?tid=*&page=*
  10. // @match http://bbs.ngacn.cc/read.php?tid=*&page=*
  11. // @match http://ngabbs.com/read.php?tid=*&page=*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15.  
  16. jQuery.noConflict();
  17. var jq=jQuery;
  18. (function(){
  19. var prog,progv=0,ti,cal
  20. function init(){
  21. prog = _$('/div','style','position:fixed;display:none;bottom:0;left:0;right:0;height:1em;background:silver;fontSize:0.3em;borderLeft:0 solid '+__COLOR.border0+';transition:border-left-width 0.3s linear 0s,0.3s')
  22.  
  23. }//
  24. function progr(){
  25. progv = 0
  26. prog.style.borderLeftWidth=0
  27. prog.style.display = 'none'
  28. if(cal)cal()
  29. }//
  30. commonui.progbar = function(v,o,f){//progress/% hidetimeout/ms
  31. if(!prog)
  32. init()
  33. if(v!=progv){
  34. if(progv==0){
  35. prog.style.display = ''
  36. cal = null
  37. }
  38. progv = v, prog.style.borderLeftWidth = (prog.offsetWidth*v/100)+'px'
  39. if(ti)
  40. clearTimeout(ti)
  41. if(v==100)
  42. ti = window.setTimeout(function(){progr()},300)
  43. else if(o)
  44. ti = window.setTimeout(function(){progr()},o)
  45. if(f)
  46. cal = f
  47. }
  48. }//
  49.  
  50. })();
  51.  
  52. (function() {
  53. if (!XMLHttpRequest)
  54. return
  55. var pageStat = {}, //{页n:[贴1,2,3,...], 页n+1:[贴1,2,3,...], ...}
  56. $ = _$, HTTP = new XMLHttpRequest(), l = location, tmp, minp, //当前最小页
  57. maxp, //当前最大页
  58. iPo, //当前第一条
  59. iPc, ot = 0, count = 1, //当前显示的总页数
  60. progr = function() {
  61. commonui.loadReadHidden.lock = 0
  62. }, progt = function(v, o) {
  63. commonui.progbar(v * 10, o ? o : 5000, v == 10 ? progr : null)
  64. }, cs = document.characterSet || document.defaultCharset || document.charset;
  65.  
  66. HTTP.onerror = function(e) {
  67. error('HTTP ERROR')
  68. }
  69.  
  70. HTTP.onload = HTTP.onabout = function(e) {
  71. progt(10)
  72. }
  73.  
  74. HTTP.onprogress = function(e) {
  75. /*
  76. if (e.lengthComputable)
  77. progv = (e.loaded / e.total)*prog.offsetWidth
  78. else if(progv = this.getResponseHeader('X-NGA-CONTENT-LENGTH'))
  79. progv = (e.loaded / progv)*prog.offsetWidth
  80. else{
  81. progv = e.loaded/100
  82. if(progv>prog.offsetWidth) progv = prog.offsetWidth
  83. }
  84. */
  85. progt(3)
  86. }
  87.  
  88. var ifp = function(o, opt) {
  89. if (opt & 1024) {
  90. if (o.nodeName == 'TBODY')
  91. return 1
  92. } else if (o.className == 'forumbox postbox')
  93. return 1
  94. }
  95. pr = function(txt, opt) {
  96. if (opt & 1024) {
  97. //console.log(txt)
  98. var x = cut(txt, ['<!--topicliststart-->', '<!--topiclistend-->', '//topicloadallstart', '//topicloadallend', ], 0, 1)
  99. if (x.length < 2)
  100. return error('parse page error')
  101. var y = cut(x[0], ["<script type='text/javascript'>", '</script>'], 0, 0)
  102. y.push(x[1])
  103. return [null, x[0], //内容
  104. y//取出内容加载脚本
  105. ]
  106. }
  107. var x = cut(txt, ['//userinfostart', '//userinfoend', '<!--postliststart-->', '<!--postlistend-->'], 0, 1)
  108. if (x.length < 2)
  109. return error('parse page error')
  110.  
  111. //去重by yuyuyzl
  112. var newList=[];
  113. cut(x[1], ['<table', '</table>'], 0, 0).forEach(function(o,i){
  114. if(o==null)return;
  115. o='<table'+o+ '</table>';
  116. idList=o.match(/post[a-z_]+[0123456789]+/g)
  117. //console.log(idList)
  118. if(idList==null){newList.push(o);return;}
  119. for(var j=0;j<idList.length;j++)if( $(o.match(/post[a-z_]+[0123456789]+/g)[j])!=null)return;
  120. newList.push(o);
  121. });
  122.  
  123. cut(x[1], ['<script>', '</script>'], 0, 0).forEach(function(o,i){
  124. if(o==null)return;
  125. o='<script>'+o+ '</script>';
  126. idList=o.match(/post[a-z_]+[0123456789]+/g)
  127. //console.log(idList)
  128. if(idList==null){newList.push(o);return;}
  129. for(var j=0;j<idList.length;j++)if( $(o.match(/post[a-z_]+[0123456789]+/g)[j])!=null)return;
  130. newList.push(o);
  131. });
  132.  
  133. var filtereddata="\n\n\n"+newList.join("\n\n")+"\n";
  134. //console.log(newList)
  135.  
  136. return [x[0], //用户信息脚本
  137. filtereddata, //内容
  138. cut(filtereddata, ['<script>', '</script>'], 0, 0)//取出内容加载脚本
  139. ]
  140. }
  141.  
  142. commonui.loadReadHiddenNS = function(p, opt) {
  143. // 页, &1替换加载指定页 &2连续加载下一页 &4连续加载上一页
  144. if (this.loadReadHidden.lock)
  145. return
  146. this.loadReadHidden.lock = 1
  147. if (!iPc) {
  148. iPc = $('m_posts_c')
  149. if (!iPc) {
  150. iPc = $('topicrows')
  151. ot |= 1024
  152. }
  153. }
  154.  
  155. opt |= ot
  156.  
  157. if (!minp) {
  158. minp = maxp = __PAGE[2]
  159. pageStat[maxp] = []
  160. for (var i = 0; i < iPc.childNodes.length; i++) {
  161. if (ifp(iPc.childNodes[i], opt))
  162. pageStat[maxp].push(iPc.childNodes[i])
  163. }
  164. }
  165.  
  166.  
  167. var ugo = __PAGE[0] + '&page=' + p
  168. HTTP.__rep = 0
  169. HTTP.abort()
  170. HTTP.open('GET', ugo)
  171. HTTP.onreadystatechange = function() {
  172. if (HTTP.readyState !== HTTP.DONE)
  173. return
  174. var all = HTTP.responseText
  175. if (HTTP.status !== 200 || HTTP.getResponseHeader("X-NGA-CONTENT-TYPE") == 'short-message') {
  176. var c = all.match(/<!--msgcodestart-->(\d+)<!--msgcodeend-->/)
  177. if (c && c[1] == 15 && HTTP.__rep < 1) {
  178. __COOKIE.setCookieInSecond('guestJs', __NOW, 1200)
  179. HTTP.__rep++
  180. return setTimeout(function() {
  181. HTTP.abort()
  182. HTTP.open('GET', ugo)
  183. HTTP.send()
  184. }, 500)
  185. }
  186. var c = all.match(/<!--msginfostart-->(.+?)<!--msginfoend-->/)
  187. if (c)
  188. return error(c[1].replace(/<br\s*\/>/g, "\n").replace(/<\/?[A-Za-z]+(\s[^>]*)?>/g, " ").replace(/^\s+|\s+$/g, ''), 2)
  189. return error('HTTP ERROR ' + HTTP.status, 2);
  190. }
  191.  
  192. progt(5)
  193.  
  194. var data = pr(all, opt)
  195.  
  196. if (commonui.eval.call(window, data[0]))
  197. return error('parse data 0 error')
  198.  
  199. progt(6)
  200.  
  201. __PAGE[2] = p
  202. if (opt & 1) {
  203. minp = maxp = p
  204. pageStat = {}
  205. count = 1
  206. iPo = null
  207. for (var i = iPc.childNodes.length - 1; i >= 0; i--) {
  208. //if(ifp(iPc.childNodes[i], opt) || iPc.childNodes[i].nodeName=='SCRIPT')
  209. iPc.removeChild(iPc.childNodes[i])
  210. }
  211. if (history.replaceState)
  212. history.replaceState('object or string', document.title, __PAGE[0] + '&page=' + p)
  213. } else if (opt & 6) {
  214.  
  215. //count++
  216. if (count > 10) {
  217. count--
  218. if (opt & 2)
  219. tmp = minp,
  220. minp++
  221. else if (opt & 4)
  222. tmp = maxp,
  223. maxp--
  224. for (var i = 0; i < pageStat[tmp].length; i++) {
  225. pageStat[tmp][i].parentNode.removeChild(pageStat[p][i])
  226. pageStat[tmp][i] = null
  227. }
  228. pageStat[tmp] = null
  229. delete pageStat[tmp]
  230. }
  231.  
  232. if (opt & 2)
  233. maxp = p,
  234. iPo = null
  235. else if (opt & 4)
  236. iPo = pageStat[minp][0],
  237. minp = p
  238. commonui.topicArg.opt |= 1
  239. //console.log('replacehis '+p)
  240. //if(history.replaceState)
  241. //history.replaceState('object or string', document.title, __PAGE[0]+'&page='+p)
  242. }
  243.  
  244. progt(7)
  245.  
  246. var c = data[1].match(/\s*<tbody/) ? $('/table') : $('/span')
  247. c.innerHTML = data[1]
  248.  
  249. pageStat[p] = []
  250. for (var i = 0; i < c.childNodes.length; i++) {
  251. if (ifp(c.childNodes[i], opt)) {
  252. pageStat[p].push(c.childNodes[i])
  253. iPc.insertBefore(c.childNodes[i], iPo)
  254. }
  255. }
  256.  
  257. progt(8)
  258.  
  259. for (var i = 0; i < data[2].length; i++) {
  260. if (commonui.eval.call(window, data[2][i]))
  261. return error('parse data 2 error')
  262. }
  263.  
  264. /*var c = document.getElementsByName('pageball')
  265. if (opt & 1) {
  266. commonui.pageBtn(c[0], {
  267. 0: __PAGE[0],
  268. 1: __PAGE[1],
  269. 2: p,
  270. 3: __PAGE[3]
  271. }, 16)
  272. commonui.pageBtn(c[1], {
  273. 0: __PAGE[0],
  274. 1: __PAGE[1],
  275. 2: p,
  276. 3: __PAGE[3]
  277. }, 8)
  278. } else {
  279. commonui.pageBtn(c[0], {
  280. 0: __PAGE[0],
  281. 1: __PAGE[1],
  282. 2: minp,
  283. 3: __PAGE[3]
  284. }, 4 | 16)
  285. commonui.pageBtn(c[1], {
  286. 0: __PAGE[0],
  287. 1: __PAGE[1],
  288. 2: maxp,
  289. 3: __PAGE[3]
  290. }, 2 | 8)
  291. }//*/
  292.  
  293. progt(9)
  294.  
  295. if (window._czc)
  296. //cnzz统计
  297. _czc.push(["_trackPageview", __PAGE[0] + '&page=' + p]);
  298.  
  299.  
  300. }
  301.  
  302. HTTP.overrideMimeType("text/html; charset=" + cs);
  303.  
  304. progt(1)
  305.  
  306. HTTP.send()
  307.  
  308. }
  309. //fe
  310.  
  311. commonui.loadReadHidden.reset = function() {
  312. tmp = null
  313. minp = null
  314. maxp = null
  315. iPo = null
  316. iPc = null
  317. ot = 0
  318. count = 1
  319. }
  320. //
  321.  
  322. var error = function(e, a) {
  323. progt(10)
  324.  
  325. console.log(e)
  326.  
  327. }
  328.  
  329. var cut = function(txt, match, offset, opt) {
  330. var m, n, r = [], start = match.shift(), end = match.shift()
  331. while (1) {
  332. m = txt.indexOf(start, offset)
  333. if (m == -1)
  334. break
  335. n = txt.indexOf(end, m)
  336. if (n == -1)
  337. break
  338. r.push(txt.substr(m + start.length, n - m - start.length))
  339. offset = n + end.length
  340. if (opt & 1) {
  341. var start = match.shift()
  342. , end = match.shift()
  343. if (!start || !end)
  344. break
  345. }
  346. }
  347. return r
  348. }
  349. //fe
  350.  
  351. }
  352. )();
  353.  
  354. jq("#pagebtop td a.invert").text("Auto").attr("href",jq("#pagebtop td a.invert").attr("href").replace(/\&page=[0-9]+/,"&page=9999"));
  355. jq("#pagebbtm td a.invert").text("Auto").attr("href",jq("#pagebbtm td a.invert").attr("href").replace(/\&page=[0-9]+/,"&page=9999"));
  356. setInterval(function(){
  357. commonui.loadReadHiddenNS(9999,2);
  358. },3000)
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址