// ==UserScript== // @name 长佩专用 | 自动翻页 只显示匿名 // @namespace http://tampermonkey.net/ // @version 0.1.3 // @description 自动翻页 只显示匿名 // @author You // @match *://allcp.net/forum.php?mod=viewthread&tid=* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; var btnRight = document.createElement("div"); btnRight.style.cssText = `position:fixed;bottom:140px;right:20px; padding:7px;width:40px;background:rgb(174,230,255); font:14px/1.5 '';color:#444;text-align:center;` btnRight.innerText = "点击显示匿名" document.body.appendChild(btnRight); var onlyAnous = false; var onoff = true; var maxPage = (function(){ let span = document.querySelector("div#pgt .pg span"); if(span){ return parseInt(span.innerText.split(" ")[2]) }else{ return 1 } })() if (document.URL.indexOf("page=") == -1) { var nextPage = 2; }else{ var nextPage = parseInt(document.URL.split("=").reverse()[0]) + 1 } var tid = document.URL.match(/&tid=\d{1,7}/) var url = `http://allcp.net/forum.php?mod=viewthread${tid}&extra=&page=${nextPage}` if (onlyAnous) { hiddenAnous(document.querySelectorAll("table.plhin")) } document.onmousewheel = function (eve) { var e = eve || window.event; if (nextPage <= maxPage ) { if (document.body.clientHeight < e.pageY + 2000) { newPage(nextPage); } }else{ if(onoff){ let notice = document.createElement("div"); notice.style.cssText = 'padding-bottom:30px;font:600 25px/2 ""; text-align:center;'; notice.innerText = "已经到底啦..." document.body.appendChild(document.createElement("hr")) document.body.appendChild(notice) onoff = false; }else{ return; } } } function newPage(nextPage) { url = url.slice(0, url.lastIndexOf("=") + 1) + nextPage; var xhr = new XMLHttpRequest(); xhr.open("get", url, false); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { callback(xhr.responseText); } } xhr.send(""); } function callback(rsp) { var d = document.createElement("div"); d.innerHTML = rsp; var nextComment = d.querySelectorAll("table.plhin") var ele = document.createElement("div"); ele.style.cssText = "diaply:flex;justify-content:space-between;width:960px;margin:0 auto;" ele.innerHTML= `
第${nextPage}页链接 >>>>>>> ${url}
` for (var i = 0; i < nextComment.length; i++) { nextComment[i].style.width = "980px"; ele.appendChild(nextComment[i]); } if (onlyAnous) { hiddenAnous(nextComment); } document.body.appendChild(ele); nextPage++; } btnRight.onclick = function(){ var aComment = document.querySelectorAll("table.plhin"); if (onlyAnous) { for (var i = 0; i < aComment.length; i++) { aComment[i].style.display = ""; btnRight.innerText = "点击显示匿名"; onlyAnous = false; } }else{ hiddenAnous(aComment); btnRight.innerText = "点击显示全部"; onlyAnous = true; } } function hiddenAnous(arr){ for (var i = 0; i < arr.length; i++) { var auth = arr[i].querySelector("div.authi").innerText.split("发表于")[0].trim(); if (auth != "匿名青花鱼") { arr[i].style.display = "none" } } } })();