自动无缝翻页

This commit is contained in:
xiu2
2020-10-11 15:17:03 +08:00
parent 5d4b7ab6b8
commit 64c04f2db1
4 changed files with 439 additions and 47 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
// ==UserScript==
// @name 吾爱破解论坛美化 - 精简多余内容
// @name 吾爱破解论坛美化
// @version 1.0.1
// @author X.I.U
// @description 精简多余内容
+211 -24
View File
@@ -1,19 +1,97 @@
// ==UserScript==
// @name 吾爱破解论坛增强 - 自动签到、翻页
// @version 1.0.5
// @version 1.0.6
// @author X.I.U
// @description 吾爱破解论坛自动签到、自动翻页
// @description 自动签到、自动无缝翻页
// @match *://www.52pojie.cn/*
// @icon https://www.52pojie.cn/favicon.ico
// @grant GM_xmlhttpRequest
// @license GPL-3.0 License
// @run-at document-end
// @namespace https://greasyfork.org/scripts/412680
// ==/UserScript==
(function() {
qianDaoBack();
qianDao();
pageLoading();
// 默认 ID 为 0
var curSite = {SiteTypeID: 0};
// 自动翻页规则
let DBSite = {
forum: {
SiteTypeID: 1
},
thread: {
SiteTypeID: 2,
pager: {
nextLink: '//div[@id="pgt"]//a[contains(text(),"下一页")][@href]',
pageElement: 'css;div#postlist > div[id^="post_"]',
HT_insert: ['css;div#postlist', 2],
replaceE: '//div[@class="pg"] | //div[@class="pgbtn"]',
}
},
guide: {
SiteTypeID: 3,
pager: {
nextLink: '//div[@id="pgt"]//a[contains(text(),"下一页")][@href]',
pageElement: 'css;div#threadlist div.bm_c table > tbody[id^="normalthread_"]',
HT_insert: ['css;div#threadlist div.bm_c table', 2],
replaceE: 'css;div.pg',
}
}
};
// 用于脚本内部判断当前 URL 类型
let SiteType = {
FORUM: DBSite.forum.SiteTypeID,
THREAD: DBSite.thread.SiteTypeID,
GUIDE: DBSite.guide.SiteTypeID
};
// URL 匹配正则表达式
var patt_forum = /\/forum-\d+-\d+\.html/,
patt_forum_2 = /mod\=forumdisplay/,
patt_thread = /\/thread-\d+-\d+\-\d+.html/,
patt_thread_2 = /mod\=viewthread/,
patt_guide = /mod\=guide\&view\=(hot|digest)/
// URL 判断
if (patt_thread.test(location.pathname) || patt_thread_2.test(location.search)){
curSite = DBSite.thread;
}else if (patt_forum.test(location.pathname) || patt_forum_2.test(location.search)){
curSite = DBSite.forum;
}else if (patt_guide.test(location.search)){
curSite = DBSite.guide;
}
curSite.pageUrl = ""; // 下一页URL
qianDaoBack(); // 先看看是不是签到跳转页面,如果是则返回
qianDao(); // 看看有没有签到
pageLoading(); // 自动翻页
// 自动翻页
function pageLoading() {
if (curSite.SiteTypeID > 0){
windowScroll(function (direction, e) {
if (direction === "down") { // 下滑才准备翻页
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
let scrollDelta = 666;
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
if (curSite.SiteTypeID === SiteType.FORUM) { // 如果是原创、精品等版块则直接点下一页就行了
var autopbn = document.querySelector('#autopbn');
if (autopbn && autopbn.innerText == "下一页 »"){ // 如果已经在加载中了,就忽略
autopbn.click();
}
}else{
ShowPager.loadMorePage();
}
}
}
});
}
}
// 自动签到
function qianDao() {
@@ -26,6 +104,7 @@
}
}
// 签到后立即返回
function qianDaoBack() {
var qiandaoback = document.querySelector('#messagetext p.alert_btnleft a');
@@ -37,25 +116,6 @@
}
}
// 自动翻页
function pageLoading() {
var patt1 = /\/forum-\d+-\d+\.html/
var patt2 = /mod\=forumdisplay/
if (patt1.test(location.pathname) || patt2.test(location.search)){
windowScroll(function (direction, e) {
if (direction === "down") { // 下滑才准备翻页
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
let scrollDelta = 666;
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
var autopbn = document.querySelector('#autopbn');
if (autopbn && autopbn.innerText == "下一页 »"){ // 如果已经在加载中了,就忽略
autopbn.click();
}
}
}
});
}
}
// 滚动条事件
function windowScroll(fn1) {
@@ -71,4 +131,131 @@
}, false);
}, 1000)
}
var ShowPager = { // 修改自 https://greasyfork.org/scripts/14178
getFullHref: function (e) {
if(e == null) return '';
"string" != typeof e && (e = e.getAttribute("href"));
var t = this.getFullHref.a;
return t || (this.getFullHref.a = t = document.createElement("a")), t.href = e, t.href;
},
createDocumentByString: function (e) {
if (e) {
if ("HTML" !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, "application/xhtml+xml");
var t;
try {
t = (new DOMParser).parseFromString(e, "text/html");
} catch (e) {
}
if (t) return t;
if (document.implementation.createHTMLDocument) t = document.implementation.createHTMLDocument("ADocument"); else try {
(t = document.cloneNode(!1)).appendChild(t.importNode(document.documentElement, !1)),
t.documentElement.appendChild(t.createElement("head")), t.documentElement.appendChild(t.createElement("body"));
} catch (e) {
}
if (t) {
var r = document.createRange();
r.selectNodeContents(document.body);
var n = r.createContextualFragment(e);
t.body.appendChild(n);
for (var a, o = {
TITLE: !0,
META: !0,
LINK: !0,
STYLE: !0,
BASE: !0
}, i = t.body, s = i.childNodes, c = s.length - 1; c >= 0; c--) o[(a = s[c]).nodeName] && i.removeChild(a);
return t;
}
} else console.error("没有找到要转成DOM的字符串");
},
loadMorePage: function () {
if (curSite.pager) {
let curPageEle = getElementByXpath(curSite.pager.nextLink);
var url = this.getFullHref(curPageEle);
//console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
if(url === '') return;
if(curSite.pageUrl === url) return;// 不会重复加载相同的页面
curSite.pageUrl = url;
// 读取下一页的数据
curSite.pager.startFilter && curSite.pager.startFilter();
GM_xmlhttpRequest({
url: url,
method: "GET",
timeout: 5000,
onload: function (response) {
try {
var newBody = ShowPager.createDocumentByString(response.responseText);
let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody);
let toElement = getAllElements(curSite.pager.HT_insert[0])[0];
if (pageElems.length >= 0) {
let addTo = "beforeend";
if (curSite.pager.HT_insert[1] == 1) addTo = "beforebegin";
// 插入新页面元素
pageElems.forEach(function (one) {
toElement.insertAdjacentElement(addTo, one);
});
// 替换待替换元素
try {
let oriE = getAllElements(curSite.pager.replaceE);
let repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
if (oriE.length === repE.length) {
for (var i = 0; i < oriE.length; i++) {
oriE[i].outerHTML = repE[i].outerHTML;
}
}
} catch (e) {
console.log(e);
}
}
} catch (e) {
console.log(e);
}
}
});
}
},
};
function getElementByXpath(e, t, r) {
r = r || document, t = t || r;
try {
return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
} catch (t) {
return void console.error("无效的xpath");
}
}
function getAllElements(e, t, r, n, o) {
let getAllElementsByXpath = function(e, t, r) {
return r = r || document, t = t || r, r.evaluate(e, t, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
var i, s = [];
if (!e) return s;
if (r = r || document, n = n || window, o = o || void 0, t = t || r, "string" == typeof e) i = 0 === e.search(/^css;/i) ? function getAllElementsByCSS(e, t) {
return (t || document).querySelectorAll(e);
}(e.slice(4), t) : getAllElementsByXpath(e, t, r); else {
if (!(i = e(r, n, o))) return s;
if (i.nodeType) return s[0] = i, s;
}
return function makeArray(e) {
var t, r, n, o = [];
if (e.pop) {
for (t = 0, r = e.length; t < r; t++) (n = e[t]) && (n.nodeType ? o.push(n) : o = o.concat(makeArray(n)));
return a()(o);
}
if (e.item) {
for (t = e.length; t;) o[--t] = e[t];
return o;
}
if (e.iterateNext) {
for (t = e.snapshotLength; t;) o[--t] = e.snapshotItem(t);
return o;
}
}(i);
}
})();
+1 -1
View File
@@ -1,5 +1,5 @@
// ==UserScript==
// @name 智友邦论坛美化 - 精简多余内容、宽屏显示
// @name 智友邦论坛美化
// @version 1.0.0
// @author X.I.U
// @description 精简多余内容、宽屏显示
+226 -21
View File
@@ -1,47 +1,252 @@
// ==UserScript==
// @name 智友邦论坛增强 - 自动签到、回复、清理置顶帖子
// @version 1.0.1
// @name 智友邦论坛增强
// @version 1.0.2
// @author X.I.U
// @description 智友邦论坛自动签到、自动回复、自动清理置顶帖子
// @description 自动签到、自动回复、自动无缝翻页、自动清理置顶帖子
// @icon http://bbs.zhiyoo.net/favicon.ico
// @match *://bbs.zhiyoo.net/*
// @grant GM_xmlhttpRequest
// @license GPL-3.0 License
// @run-at document-end
// @namespace https://greasyfork.org/scripts/412362
// ==/UserScript==
(function() {
var qiandao_Redirect_URL = `http://bbs.zhiyoo.net/forum.php?mod=forumdisplay&fid=42&filter=author&orderby=dateline`; // 签到后跳转的URL
// 签到后跳转的URL
var qiandao_Redirect_URL = `http://bbs.zhiyoo.net/forum.php?mod=forumdisplay&fid=42&filter=author&orderby=dateline`;
// 默认 ID 为 0
var curSite = {SiteTypeID: 0};
// 自动翻页规则
let DBSite = {
forumdisplay: {
SiteTypeID: 1,
pager: {
nextLink: '//a[@class="nxt"][@href]',
pageElement: 'css;table#threadlisttableid > tbody[id^="normalthread_"]',
HT_insert: ['css;table#threadlisttableid', 2],
replaceE: 'css;div.pg',
}
}
};
// 用于脚本内部判断当前 URL 类型
let SiteType = {
FORUMDISPLAY: DBSite.forumdisplay.SiteTypeID
};
if (location.pathname === '/plugin.php'){
if (location.href === 'http://bbs.zhiyoo.net/plugin.php?id=dsu_paulsign:sign'){ // 如果被重定向到签到页面
if(document.getElementById("yl"))
{
document.querySelector('#yl').click();
document.querySelector('.tr3.tac div a').click();
}
setTimeout(location.href=qiandao_Redirect_URL, 2000); // 跳转到指定URL
qiandao(); // 自动签到
}
}
else if(location.pathname === '/forum.php'){
switch(getQueryVariable("mod"))
{
case 'viewthread': // 浏览帖子内容,自动回复,回复过就定位到底部(隐藏内容区域)
if (document.getElementsByClassName("locked").length > 0){
document.querySelector('#saya_fastreply_div div').click();
setTimeout("document.getElementById('fastpostsubmit').click()", 200);
}
setTimeout("location.hash='#footer'", 300);
case 'viewthread': // 浏览帖子内容
autoReply(); // 自动回复,回复过就定位到底部(隐藏内容区域)
break;
case 'forumdisplay': // 浏览帖子列表,清理置顶帖子
var showhide = document.querySelectorAll("a.showhide.y");
if (showhide.length > 0){
showhide.forEach(el=>el.click());
}
case 'forumdisplay': // 浏览帖子列表
curSite = DBSite.forumdisplay;
curSite.pageUrl = ""; // 下一页URL
cleanTop(); // 清理置顶帖子
pageLoading(); // 自动翻页
break;
}
}
// 自动翻页
function pageLoading() {
if (curSite.SiteTypeID > 0){
windowScroll(function (direction, e) {
if (direction === "down") { // 下滑才准备翻页
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
let scrollDelta = 666;
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
ShowPager.loadMorePage();
}
}
});
}
}
// 自动签到
function qiandao(){
if(document.getElementById("yl"))
{
document.querySelector('#yl').click();
document.querySelector('.tr3.tac div a').click();
}
setTimeout(location.href=qiandao_Redirect_URL, 2000); // 跳转到指定URL
}
// 自动回复
function autoReply(){
if (document.getElementsByClassName("locked").length > 0){
document.querySelector('#saya_fastreply_div div').click();
setTimeout("document.getElementById('fastpostsubmit').click()", 200);
}
setTimeout("location.hash='#footer'", 300);
}
// 清理置顶帖子
function cleanTop(){
var showhide = document.querySelectorAll("a.showhide.y");
if (showhide.length > 0){
showhide.forEach(el=>el.click());
}
}
// 滚动条事件
function windowScroll(fn1) {
var beforeScrollTop = document.documentElement.scrollTop,
fn = fn1 || function () {};
setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
window.addEventListener("scroll", function (e) {
var afterScrollTop = document.documentElement.scrollTop,
delta = afterScrollTop - beforeScrollTop;
if (delta == 0) return false;
fn(delta > 0 ? "down" : "up", e);
beforeScrollTop = afterScrollTop;
}, false);
}, 1000)
}
var ShowPager = { // 修改自 https://greasyfork.org/scripts/14178
getFullHref: function (e) {
if(e == null) return '';
"string" != typeof e && (e = e.getAttribute("href"));
var t = this.getFullHref.a;
return t || (this.getFullHref.a = t = document.createElement("a")), t.href = e, t.href;
},
createDocumentByString: function (e) {
if (e) {
if ("HTML" !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, "application/xhtml+xml");
var t;
try {
t = (new DOMParser).parseFromString(e, "text/html");
} catch (e) {
}
if (t) return t;
if (document.implementation.createHTMLDocument) t = document.implementation.createHTMLDocument("ADocument"); else try {
(t = document.cloneNode(!1)).appendChild(t.importNode(document.documentElement, !1)),
t.documentElement.appendChild(t.createElement("head")), t.documentElement.appendChild(t.createElement("body"));
} catch (e) {
}
if (t) {
var r = document.createRange();
r.selectNodeContents(document.body);
var n = r.createContextualFragment(e);
t.body.appendChild(n);
for (var a, o = {
TITLE: !0,
META: !0,
LINK: !0,
STYLE: !0,
BASE: !0
}, i = t.body, s = i.childNodes, c = s.length - 1; c >= 0; c--) o[(a = s[c]).nodeName] && i.removeChild(a);
return t;
}
} else console.error("没有找到要转成DOM的字符串");
},
loadMorePage: function () {
if (curSite.pager) {
let curPageEle = getElementByXpath(curSite.pager.nextLink);
var url = this.getFullHref(curPageEle);
console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
if(url === '') return;
if(curSite.pageUrl === url) return;// 不会重复加载相同的页面
curSite.pageUrl = url;
// 读取下一页的数据
curSite.pager.startFilter && curSite.pager.startFilter();
GM_xmlhttpRequest({
url: url,
method: "GET",
timeout: 5000,
onload: function (response) {
try {
var newBody = ShowPager.createDocumentByString(response.responseText);
let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody);
let toElement = getAllElements(curSite.pager.HT_insert[0])[0];
if (pageElems.length >= 0) {
let addTo = "beforeend";
if (curSite.pager.HT_insert[1] == 1) addTo = "beforebegin";
// 插入新页面元素
pageElems.forEach(function (one) {
toElement.insertAdjacentElement(addTo, one);
});
// 替换待替换元素
try {
let oriE = getAllElements(curSite.pager.replaceE);
let repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
if (oriE.length === repE.length) {
for (var i = 0; i < oriE.length; i++) {
oriE[i].outerHTML = repE[i].outerHTML;
}
}
} catch (e) {
console.log(e);
}
}
} catch (e) {
console.log(e);
}
}
});
}
},
};
function getElementByXpath(e, t, r) {
r = r || document, t = t || r;
try {
return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
} catch (t) {
return void console.error("无效的xpath");
}
}
function getAllElements(e, t, r, n, o) {
let getAllElementsByXpath = function(e, t, r) {
return r = r || document, t = t || r, r.evaluate(e, t, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
var i, s = [];
if (!e) return s;
if (r = r || document, n = n || window, o = o || void 0, t = t || r, "string" == typeof e) i = 0 === e.search(/^css;/i) ? function getAllElementsByCSS(e, t) {
return (t || document).querySelectorAll(e);
}(e.slice(4), t) : getAllElementsByXpath(e, t, r); else {
if (!(i = e(r, n, o))) return s;
if (i.nodeType) return s[0] = i, s;
}
return function makeArray(e) {
var t, r, n, o = [];
if (e.pop) {
for (t = 0, r = e.length; t < r; t++) (n = e[t]) && (n.nodeType ? o.push(n) : o = o.concat(makeArray(n)));
return a()(o);
}
if (e.item) {
for (t = e.length; t;) o[--t] = e[t];
return o;
}
if (e.iterateNext) {
for (t = e.snapshotLength; t;) o[--t] = e.snapshotItem(t);
return o;
}
}(i);
}
})();
// 获取GET参数
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);