// ==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'; if (document.URL.indexOf("page=") == -1) { console.log( 2); var pageNext = 2; }else{ console.log( 1); var pageNext = 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=${pageNext}` console.log( pageNext,tid,url); 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; if (onlyAnous) { hiddenAnous(document.querySelectorAll("table.plhin")) } document.onmousewheel = function (eve) { var e = eve || window.event; if (document.body.clientHeight < e.pageY + 2000) { newPage(pageNext); } } function newPage(pageNext) { url = url.slice(0, url.lastIndexOf("=") + 1) + pageNext; var xhr = new XMLHttpRequest(); xhr.open("get", url, false); xhr.onreadystatechange = function () { console.log("xhr.ready", xhr.readyState, xhr.status) 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= `
本页链接 >>>>>>> ${url}
` for (var i = 0; i < nextComment.length; i++) { nextComment[i].style.width = "980px"; ele.appendChild(nextComment[i]); } hiddenAnous(nextComment); document.body.appendChild(ele); pageNext++; } btnRight.onclick = function(){ console.log( "onclick",onlyAnous,btnRight.innerText); 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" } } } })();