mirror of
https://github.com/XIU2/UserScript.git
synced 2026-09-07 11:27:41 +00:00
优化 代码
This commit is contained in:
+83
-83
@@ -194,29 +194,6 @@
|
||||
}
|
||||
|
||||
|
||||
// 自动翻页
|
||||
function pageLoading() {
|
||||
if (curSite.SiteTypeID > 0){
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === "down") { // 下滑才准备翻页
|
||||
let 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) { // 如果是各版块帖子列表则直接点下一页就行了
|
||||
let autopbn = document.querySelector('#autopbn');
|
||||
if (autopbn && autopbn.innerText == "下一页 »"){ // 如果已经在加载中了,就忽略
|
||||
autopbn.click();
|
||||
}
|
||||
}else{
|
||||
ShowPager.loadMorePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 自动回复
|
||||
function autoReply(){
|
||||
if (loginStatus){
|
||||
@@ -271,58 +248,73 @@
|
||||
}
|
||||
|
||||
|
||||
// 自动翻页
|
||||
function pageLoading() {
|
||||
if (curSite.SiteTypeID > 0){
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === 'down') { // 下滑才准备翻页
|
||||
let 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) { // 如果是各版块帖子列表则直接点下一页就行了
|
||||
let autopbn = document.querySelector('#autopbn');
|
||||
if (autopbn && autopbn.innerText == "下一页 »"){ // 如果已经在加载中了,就忽略
|
||||
autopbn.click();
|
||||
}
|
||||
}else{
|
||||
ShowPager.loadMorePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 滚动条事件
|
||||
function windowScroll(fn1) {
|
||||
var beforeScrollTop = document.documentElement.scrollTop,
|
||||
fn = fn1 || function () {};
|
||||
setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
|
||||
window.addEventListener("scroll", function (e) {
|
||||
window.addEventListener('scroll', function (e) {
|
||||
var afterScrollTop = document.documentElement.scrollTop,
|
||||
delta = afterScrollTop - beforeScrollTop;
|
||||
if (delta == 0) return false;
|
||||
fn(delta > 0 ? "down" : "up", e);
|
||||
fn(delta > 0 ? 'down' : 'up', e);
|
||||
beforeScrollTop = afterScrollTop;
|
||||
}, false);
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
|
||||
var ShowPager = { // 修改自 https://greasyfork.org/scripts/14178
|
||||
// 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
|
||||
var ShowPager = {
|
||||
getFullHref: function (e) {
|
||||
if(e == null) return '';
|
||||
"string" != typeof e && (e = e.getAttribute("href"));
|
||||
'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;
|
||||
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");
|
||||
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) {
|
||||
}
|
||||
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 (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();
|
||||
var r = document.createRange(),
|
||||
n = r.createContextualFragment(e);
|
||||
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);
|
||||
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的字符串");
|
||||
} else console.error('没有找到要转成 DOM 的字符串');
|
||||
},
|
||||
loadMorePage: function () {
|
||||
if (curSite.pager) {
|
||||
@@ -371,45 +363,53 @@
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
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 getElementByCSS(css, contextNode = document) {
|
||||
return contextNode.querySelector(css);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
function getAllElementsByCSS(css, contextNode = document) {
|
||||
return [].slice.call(contextNode.querySelectorAll(css));
|
||||
}
|
||||
function getElementByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
try {
|
||||
const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
||||
// 应该总是返回一个元素节点
|
||||
return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
|
||||
} catch (err) {
|
||||
throw new Error(`Invalid xpath: ${xpath}`);
|
||||
}
|
||||
if (e.item) {
|
||||
for (t = e.length; t;) o[--t] = e[t];
|
||||
return o;
|
||||
}
|
||||
function getAllElementsByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
const result = [];
|
||||
try {
|
||||
const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
for (let i = 0; i < query.snapshotLength; i++) {
|
||||
const node = query.snapshotItem(i);
|
||||
// 如果是 Element 节点
|
||||
if (node.nodeType === 1) result.push(node);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`无效 Xpath: ${xpath}`);
|
||||
}
|
||||
if (e.iterateNext) {
|
||||
for (t = e.snapshotLength; t;) o[--t] = e.snapshotItem(t);
|
||||
return o;
|
||||
return result;
|
||||
}
|
||||
function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
|
||||
if (!selector) return [];
|
||||
contextNode = contextNode || doc;
|
||||
if (typeof selector === 'string') {
|
||||
if (selector.search(/^css;/i) === 0) {
|
||||
return getAllElementsByCSS(selector.slice(4), contextNode);
|
||||
} else {
|
||||
return getAllElementsByXpath(selector, contextNode, doc);
|
||||
}
|
||||
} else {
|
||||
const query = selector(doc, win, _cplink);
|
||||
if (!Array.isArray(query)) {
|
||||
throw new Error('getAllElements 返回错误类型');
|
||||
} else {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}(i);
|
||||
}
|
||||
})();
|
||||
+83
-84
@@ -184,30 +184,6 @@
|
||||
pageLoading(); // 自动翻页
|
||||
|
||||
|
||||
// 自动翻页
|
||||
function pageLoading() {
|
||||
if (!menu_value('menu_pageLoading')) return
|
||||
if (curSite.SiteTypeID > 0) {
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === "down") { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
|
||||
let scrollDelta = curSite.pager.scrollDelta;
|
||||
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
|
||||
if (curSite.pager.type === 1) {
|
||||
ShowPager.loadMorePage();
|
||||
} else {
|
||||
let autopbn = document.querySelector(curSite.pager.nextLink);
|
||||
if (autopbn && autopbn.innerText == curSite.pager.nextText) { // 如果正在加载,就不再点击
|
||||
autopbn.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 自动签到(后台)
|
||||
function qianDao() {
|
||||
if (!menu_value('menu_autoClockIn')) return
|
||||
@@ -259,60 +235,75 @@
|
||||
}
|
||||
|
||||
|
||||
// 自动翻页
|
||||
function pageLoading() {
|
||||
if (!menu_value('menu_pageLoading')) return
|
||||
if (curSite.SiteTypeID > 0) {
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === "down") { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
|
||||
let scrollDelta = curSite.pager.scrollDelta;
|
||||
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
|
||||
if (curSite.pager.type === 1) {
|
||||
ShowPager.loadMorePage();
|
||||
} else {
|
||||
let autopbn = document.querySelector(curSite.pager.nextLink);
|
||||
if (autopbn && autopbn.innerText == curSite.pager.nextText) { // 如果正在加载,就不再点击
|
||||
autopbn.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 滚动条事件
|
||||
function windowScroll(fn1) {
|
||||
var beforeScrollTop = document.documentElement.scrollTop,
|
||||
fn = fn1 || function () {};
|
||||
setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
|
||||
window.addEventListener("scroll", function (e) {
|
||||
window.addEventListener('scroll', function (e) {
|
||||
var afterScrollTop = document.documentElement.scrollTop,
|
||||
delta = afterScrollTop - beforeScrollTop;
|
||||
if (delta == 0) return false;
|
||||
fn(delta > 0 ? "down" : "up", e);
|
||||
fn(delta > 0 ? 'down' : 'up', e);
|
||||
beforeScrollTop = afterScrollTop;
|
||||
}, false);
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
|
||||
// 自动无缝翻页,修改自 https://greasyfork.org/scripts/14178
|
||||
// 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
|
||||
function showPager() {
|
||||
ShowPager = {
|
||||
getFullHref: function (e) {
|
||||
if(e == null) return '';
|
||||
"string" != typeof e && (e = e.getAttribute("href"));
|
||||
'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;
|
||||
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");
|
||||
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) {
|
||||
}
|
||||
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 (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();
|
||||
var r = document.createRange(),
|
||||
n = r.createContextualFragment(e);
|
||||
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);
|
||||
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的字符串");
|
||||
} else console.error('没有找到要转成 DOM 的字符串');
|
||||
},
|
||||
loadMorePage: function () {
|
||||
if (curSite.pager) {
|
||||
@@ -364,45 +355,53 @@
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
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 getElementByCSS(css, contextNode = document) {
|
||||
return contextNode.querySelector(css);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
function getAllElementsByCSS(css, contextNode = document) {
|
||||
return [].slice.call(contextNode.querySelectorAll(css));
|
||||
}
|
||||
function getElementByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
try {
|
||||
const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
||||
// 应该总是返回一个元素节点
|
||||
return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
|
||||
} catch (err) {
|
||||
throw new Error(`Invalid xpath: ${xpath}`);
|
||||
}
|
||||
if (e.item) {
|
||||
for (t = e.length; t;) o[--t] = e[t];
|
||||
return o;
|
||||
}
|
||||
function getAllElementsByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
const result = [];
|
||||
try {
|
||||
const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
for (let i = 0; i < query.snapshotLength; i++) {
|
||||
const node = query.snapshotItem(i);
|
||||
// 如果是 Element 节点
|
||||
if (node.nodeType === 1) result.push(node);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`无效 Xpath: ${xpath}`);
|
||||
}
|
||||
if (e.iterateNext) {
|
||||
for (t = e.snapshotLength; t;) o[--t] = e.snapshotItem(t);
|
||||
return o;
|
||||
return result;
|
||||
}
|
||||
function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
|
||||
if (!selector) return [];
|
||||
contextNode = contextNode || doc;
|
||||
if (typeof selector === 'string') {
|
||||
if (selector.search(/^css;/i) === 0) {
|
||||
return getAllElementsByCSS(selector.slice(4), contextNode);
|
||||
} else {
|
||||
return getAllElementsByXpath(selector, contextNode, doc);
|
||||
}
|
||||
} else {
|
||||
const query = selector(doc, win, _cplink);
|
||||
if (!Array.isArray(query)) {
|
||||
throw new Error('getAllElements 返回错误类型');
|
||||
} else {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}(i);
|
||||
}
|
||||
})();
|
||||
+65
-72
@@ -1,6 +1,6 @@
|
||||
// ==UserScript==
|
||||
// @name 自动无缝翻页
|
||||
// @version 1.4.5
|
||||
// @version 1.4.6
|
||||
// @author X.I.U
|
||||
// @description 自动无缝翻页,目前支持:所有「Discuz!、Flarum」论坛、百度、豆瓣、微博、千图网、3DM、游侠网、游民星空、423Down、APPHOT、不死鸟、亿破姐、小众软件、微当下载、落尘之木、异次元软件、老殁殁漂遥、异星软件空间、古风漫画网、RARBG、PubMed、AfreecaTV、AlphaCoders、FitGirl Repacks...
|
||||
// @match *://*/*
|
||||
@@ -674,79 +674,13 @@
|
||||
} else if (webType === 3) {
|
||||
curSite = DBSite.flarum;
|
||||
}
|
||||
|
||||
|
||||
curSite.pageUrl = ''; // 下一页URL
|
||||
pageLoading(); // 自动无缝翻页
|
||||
|
||||
|
||||
// 自动无缝翻页
|
||||
function pageLoading() {
|
||||
if (curSite.SiteTypeID > 0) {
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === 'down') { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop,
|
||||
scrollHeight = window.innerHeight || document.documentElement.clientHeight,
|
||||
scrollDelta = curSite.pager.scrollDelta;
|
||||
if (curSite.pager.type === 3) { // 翻页类型 3
|
||||
let scrollElement = document.querySelector(curSite.pager.scrollElement);
|
||||
//console.log(scrollElement.offsetTop - (scrollTop + scrollHeight), scrollDelta, curSite.SiteTypeID)
|
||||
if (scrollElement.offsetTop - (scrollTop + scrollHeight) <= scrollDelta) {
|
||||
if (curSite.SiteTypeID === SiteType.GAMERSKY_GL) curSite.pager.scrollDelta -= 800 // 游民星空 gl 的比较奇葩,需要特殊处理下
|
||||
ShowPager.loadMorePage();
|
||||
}
|
||||
} else {
|
||||
if (document.documentElement.scrollHeight <= scrollHeight + scrollTop + scrollDelta) {
|
||||
if (curSite.pager.type === 2) { // 翻页类型 2
|
||||
if (curSite.SiteTypeID > 0) { // 如果指定了间隔时间,那么就依靠这个判断时间到了没有~
|
||||
let autopbn = document.querySelector(curSite.pager.nextLink);
|
||||
if (autopbn) { // 寻找下一页链接
|
||||
if (!curSite.pager.nextText) { // 如果没有指定 nextText 就直接点击
|
||||
autopbn.click();
|
||||
} else if (autopbn.textContent.indexOf(curSite.pager.nextText) > -1){ // 如果指定了 nextText 就需要判断后再点击(避免已经在加载了,还重复点击)
|
||||
autopbn.click();
|
||||
}
|
||||
// 对于没有按钮文字变化的按钮,可以手动指定间隔时间
|
||||
if (curSite.pager.intervals) {
|
||||
let _SiteTypeID = curSite.SiteTypeID;
|
||||
curSite.SiteTypeID = 0;
|
||||
setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (curSite.pager.type === 1) { // 翻页类型 1
|
||||
ShowPager.loadMorePage();
|
||||
} else if (curSite.pager.type === 4) { // 翻页类型 4
|
||||
if (curSite.SiteTypeID > 0) {
|
||||
curSite.pager.functionNext();
|
||||
if (curSite.pager.intervals) {
|
||||
let _SiteTypeID = curSite.SiteTypeID;
|
||||
curSite.SiteTypeID = 0;
|
||||
setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*function getElementToPageTop(el) {
|
||||
if(el.parentElement) {
|
||||
return getElementToPageTop(el.parentElement) + el.offsetTop
|
||||
}
|
||||
return el.offsetTop
|
||||
}*/
|
||||
|
||||
|
||||
// 隐藏帖子内的 [下一页] 按钮(Discuz! 论坛)
|
||||
function hidePgbtn() {
|
||||
let style_hidePgbtn = document.createElement('style');
|
||||
style_hidePgbtn.innerHTML = `.pgbtn {display: none;}`;
|
||||
document.head.appendChild(style_hidePgbtn);
|
||||
document.lastChild.appendChild(document.createElement('style')).textContent = '.pgbtn {display: none;}';
|
||||
}
|
||||
|
||||
|
||||
@@ -891,6 +825,68 @@
|
||||
}
|
||||
|
||||
|
||||
// 自动无缝翻页
|
||||
function pageLoading() {
|
||||
if (curSite.SiteTypeID > 0) {
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === 'down') { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop,
|
||||
scrollHeight = window.innerHeight || document.documentElement.clientHeight,
|
||||
scrollDelta = curSite.pager.scrollDelta;
|
||||
if (curSite.pager.type === 3) { // 翻页类型 3
|
||||
let scrollElement = document.querySelector(curSite.pager.scrollElement);
|
||||
//console.log(scrollElement.offsetTop - (scrollTop + scrollHeight), scrollDelta, curSite.SiteTypeID)
|
||||
if (scrollElement.offsetTop - (scrollTop + scrollHeight) <= scrollDelta) {
|
||||
if (curSite.SiteTypeID === SiteType.GAMERSKY_GL) curSite.pager.scrollDelta -= 800 // 游民星空 gl 的比较奇葩,需要特殊处理下
|
||||
ShowPager.loadMorePage();
|
||||
}
|
||||
} else {
|
||||
if (document.documentElement.scrollHeight <= scrollHeight + scrollTop + scrollDelta) {
|
||||
if (curSite.pager.type === 2) { // 翻页类型 2
|
||||
if (curSite.SiteTypeID > 0) { // 如果指定了间隔时间,那么就依靠这个判断时间到了没有~
|
||||
let autopbn = document.querySelector(curSite.pager.nextLink);
|
||||
if (autopbn) { // 寻找下一页链接
|
||||
if (!curSite.pager.nextText) { // 如果没有指定 nextText 就直接点击
|
||||
autopbn.click();
|
||||
} else if (autopbn.textContent.indexOf(curSite.pager.nextText) > -1){ // 如果指定了 nextText 就需要判断后再点击(避免已经在加载了,还重复点击)
|
||||
autopbn.click();
|
||||
}
|
||||
// 对于没有按钮文字变化的按钮,可以手动指定间隔时间
|
||||
if (curSite.pager.intervals) {
|
||||
let _SiteTypeID = curSite.SiteTypeID;
|
||||
curSite.SiteTypeID = 0;
|
||||
setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (curSite.pager.type === 1) { // 翻页类型 1
|
||||
ShowPager.loadMorePage();
|
||||
} else if (curSite.pager.type === 4) { // 翻页类型 4
|
||||
if (curSite.SiteTypeID > 0) {
|
||||
curSite.pager.functionNext();
|
||||
if (curSite.pager.intervals) {
|
||||
let _SiteTypeID = curSite.SiteTypeID;
|
||||
curSite.SiteTypeID = 0;
|
||||
setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*function getElementToPageTop(el) {
|
||||
if(el.parentElement) {
|
||||
return getElementToPageTop(el.parentElement) + el.offsetTop
|
||||
}
|
||||
return el.offsetTop
|
||||
}*/
|
||||
|
||||
|
||||
// 启用/禁用 (当前网站)
|
||||
function menu_disable(type) {
|
||||
switch(type) {
|
||||
@@ -1014,10 +1010,7 @@
|
||||
if(e == null) return '';
|
||||
'string' != typeof e && (e = e.getAttribute('href'));
|
||||
var t = this.getFullHref.a;
|
||||
if (t) {return t}
|
||||
((this.getFullHref.a = t = document.createElement('a')), t.href = e, t.href)
|
||||
if (t.href) {return t.href}
|
||||
//return t || ((this.getFullHref.a = t = document.createElement('a')), t.href = e, t.href);
|
||||
return t || (this.getFullHref.a = t = document.createElement('a')), (t.href = e), t.href;
|
||||
},
|
||||
createDocumentByString: function (e) {
|
||||
if (e) {
|
||||
|
||||
+90
-90
@@ -446,37 +446,6 @@
|
||||
}*/
|
||||
|
||||
|
||||
// 自动翻页
|
||||
function pageLoading() {
|
||||
if (!menu_value('menu_pageLoading')) return
|
||||
if (curSite.SiteTypeID > 0){
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === "down") { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
|
||||
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + 999) {
|
||||
if (curSite.SiteTypeID === SiteType.FORUM) { // 如果是各版块帖子列表则直接点下一页就行了
|
||||
let autopbn = document.querySelector('#autopbn');
|
||||
if (autopbn && autopbn.innerText === "下一页 »"){ // 如果已经在加载中了,就忽略
|
||||
autopbn.click();
|
||||
let timer = setInterval(function(){ // 在下一页加载完成后
|
||||
if (document.querySelector('#autopbn').innerText === "下一页 »") {
|
||||
if (menu_value('menu_delate255')) delate255(); // 隐藏 255 权限帖子
|
||||
if (menu_value('menu_blockUsers')) blockUsers('forum'); // 屏蔽用户(黑名单)
|
||||
if (menu_value('menu_blockKeywords')) blockKeywords(); // 屏蔽关键词(帖子标题)
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
}else{
|
||||
ShowPager.loadMorePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 自动显示帖子内被隐藏的回复
|
||||
function showPosts() {
|
||||
if(menu_value('menu_showhide')){
|
||||
@@ -550,58 +519,81 @@
|
||||
}
|
||||
|
||||
|
||||
// 自动翻页
|
||||
function pageLoading() {
|
||||
if (!menu_value('menu_pageLoading')) return
|
||||
if (curSite.SiteTypeID > 0){
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === "down") { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
|
||||
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + 999) {
|
||||
if (curSite.SiteTypeID === SiteType.FORUM) { // 如果是各版块帖子列表则直接点下一页就行了
|
||||
let autopbn = document.querySelector('#autopbn');
|
||||
if (autopbn && autopbn.innerText === "下一页 »"){ // 如果已经在加载中了,就忽略
|
||||
autopbn.click();
|
||||
let timer = setInterval(function(){ // 在下一页加载完成后
|
||||
if (document.querySelector('#autopbn').innerText === "下一页 »") {
|
||||
if (menu_value('menu_delate255')) delate255(); // 隐藏 255 权限帖子
|
||||
if (menu_value('menu_blockUsers')) blockUsers('forum'); // 屏蔽用户(黑名单)
|
||||
if (menu_value('menu_blockKeywords')) blockKeywords(); // 屏蔽关键词(帖子标题)
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
}else{
|
||||
ShowPager.loadMorePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 滚动条事件
|
||||
function windowScroll(fn1) {
|
||||
var beforeScrollTop = document.documentElement.scrollTop,
|
||||
fn = fn1 || function () {};
|
||||
setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
|
||||
window.addEventListener("scroll", function (e) {
|
||||
window.addEventListener('scroll', function (e) {
|
||||
var afterScrollTop = document.documentElement.scrollTop,
|
||||
delta = afterScrollTop - beforeScrollTop;
|
||||
if (delta == 0) return false;
|
||||
fn(delta > 0 ? "down" : "up", e);
|
||||
fn(delta > 0 ? 'down' : 'up', e);
|
||||
beforeScrollTop = afterScrollTop;
|
||||
}, false);
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
|
||||
var ShowPager = { // 修改自 https://greasyfork.org/scripts/14178
|
||||
// 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
|
||||
var ShowPager = {
|
||||
getFullHref: function (e) {
|
||||
if(e == null) return '';
|
||||
"string" != typeof e && (e = e.getAttribute("href"));
|
||||
'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;
|
||||
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");
|
||||
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) {
|
||||
}
|
||||
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 (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();
|
||||
var r = document.createRange(),
|
||||
n = r.createContextualFragment(e);
|
||||
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);
|
||||
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的字符串");
|
||||
} else console.error('没有找到要转成 DOM 的字符串');
|
||||
},
|
||||
loadMorePage: function () {
|
||||
if (curSite.pager) {
|
||||
@@ -657,46 +649,54 @@
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
function getElementByXpath(e, t, r) {
|
||||
r = r || document, t = t || r;
|
||||
function getElementByCSS(css, contextNode = document) {
|
||||
return contextNode.querySelector(css);
|
||||
}
|
||||
function getAllElementsByCSS(css, contextNode = document) {
|
||||
return [].slice.call(contextNode.querySelectorAll(css));
|
||||
}
|
||||
function getElementByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
try {
|
||||
return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
} catch (t) {
|
||||
return void console.error("无效的xpath");
|
||||
const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
||||
// 应该总是返回一个元素节点
|
||||
return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
|
||||
} catch (err) {
|
||||
throw new Error(`Invalid xpath: ${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);
|
||||
function getAllElementsByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
const result = [];
|
||||
try {
|
||||
const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
for (let i = 0; i < query.snapshotLength; i++) {
|
||||
const node = query.snapshotItem(i);
|
||||
// 如果是 Element 节点
|
||||
if (node.nodeType === 1) result.push(node);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`无效 Xpath: ${xpath}`);
|
||||
}
|
||||
|
||||
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 result;
|
||||
}
|
||||
function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
|
||||
if (!selector) return [];
|
||||
contextNode = contextNode || doc;
|
||||
if (typeof selector === 'string') {
|
||||
if (selector.search(/^css;/i) === 0) {
|
||||
return getAllElementsByCSS(selector.slice(4), contextNode);
|
||||
} else {
|
||||
return getAllElementsByXpath(selector, contextNode, doc);
|
||||
}
|
||||
} else {
|
||||
const query = selector(doc, win, _cplink);
|
||||
if (!Array.isArray(query)) {
|
||||
throw new Error('getAllElements 返回错误类型');
|
||||
} else {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+68
-68
@@ -89,7 +89,7 @@
|
||||
pageElement: 'css;.cell.item',
|
||||
HT_insert: ['//div[@id="Main"]//div[@class="box"]//div[@class="cell"][last()]', 1],
|
||||
replaceE: 'css;#Main > .box > .cell[style]:not(.item) > table',
|
||||
scrollDelta: 1000
|
||||
scrollDelta: 1500
|
||||
},
|
||||
function: {
|
||||
after: linksBlank,
|
||||
@@ -104,7 +104,7 @@
|
||||
pageElement: 'css;#notifications > div',
|
||||
HT_insert: ['css;#notifications', 3],
|
||||
replaceE: 'css;#Main > .box > .cell[style] > table',
|
||||
scrollDelta: 1000
|
||||
scrollDelta: 1500
|
||||
},
|
||||
function: {
|
||||
after: linksBlank,
|
||||
@@ -119,7 +119,7 @@
|
||||
pageElement: '//div[@id="Main"]//div[@class="box"]//div[@class="dock_area"] | //*[@id="Main"]//div[@class="box"]//div[@class="inner"] | //*[@id="Main"]//div[@class="box"]//div[@class="dock_area"][last()]/following-sibling::div[@class="cell"][1]',
|
||||
HT_insert: ['//div[@id="Main"]//div[@class="box"]//div[@class="cell"][last()]', 1],
|
||||
replaceE: 'css;#Main > .box > .cell[style] > table',
|
||||
scrollDelta: 1000
|
||||
scrollDelta: 1500
|
||||
},
|
||||
function: {
|
||||
after: linksBlank,
|
||||
@@ -134,7 +134,7 @@
|
||||
pageElement: 'css;#TopicsNode > div',
|
||||
HT_insert: ['css;#TopicsNode', 3],
|
||||
replaceE: 'css;#Main > .box > .cell[style] > table',
|
||||
scrollDelta: 1000
|
||||
scrollDelta: 1500
|
||||
},
|
||||
function: {
|
||||
after: linksBlank,
|
||||
@@ -149,7 +149,7 @@
|
||||
pageElement: 'css;.cell[id^="r_"]',
|
||||
HT_insert: ['//div[starts-with(@id, "r_")][last()]/following-sibling::div[@class="cell"][1]', 1],
|
||||
replaceE: 'css;#Main > .box > .cell[style] > table',
|
||||
scrollDelta: 1000
|
||||
scrollDelta: 1500
|
||||
}
|
||||
},
|
||||
reply_positive: { // 帖子内容页(正序)
|
||||
@@ -160,7 +160,7 @@
|
||||
pageElement: 'css;.cell[id^="r_"]',
|
||||
HT_insert: ['//div[starts-with(@id, "r_")][1]', 1],
|
||||
replaceE: 'css;#Main > .box > .cell[style] > table',
|
||||
scrollDelta: 1000
|
||||
scrollDelta: 1500
|
||||
}
|
||||
},
|
||||
balance: { // 账户余额页
|
||||
@@ -171,7 +171,7 @@
|
||||
pageElement: '//div[@id="Main"]//div[@class="cell"][last()]/preceding-sibling::div[1]//tr[position()>1]',
|
||||
HT_insert: ['//div[@id="Main"]//div[@class="cell"][last()]/preceding-sibling::div[1]//tr[last()]', 4],
|
||||
replaceE: 'css;#Main > .box > .cell[style] > table',
|
||||
scrollDelta: 700
|
||||
scrollDelta: 1000
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -366,7 +366,7 @@
|
||||
function pageLoading() {
|
||||
if (curSite.SiteTypeID > 0){
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === "down") { // 下滑才准备翻页
|
||||
if (direction === 'down') { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
|
||||
//console.log(document.documentElement.scrollHeight)
|
||||
let scrollDelta = curSite.pager.scrollDelta;
|
||||
@@ -391,59 +391,51 @@
|
||||
var beforeScrollTop = document.documentElement.scrollTop,
|
||||
fn = fn1 || function () {};
|
||||
setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
|
||||
window.addEventListener("scroll", function (e) {
|
||||
window.addEventListener('scroll', function (e) {
|
||||
var afterScrollTop = document.documentElement.scrollTop,
|
||||
delta = afterScrollTop - beforeScrollTop;
|
||||
if (delta == 0) return false;
|
||||
fn(delta > 0 ? "down" : "up", e);
|
||||
fn(delta > 0 ? 'down' : 'up', e);
|
||||
beforeScrollTop = afterScrollTop;
|
||||
}, false);
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
|
||||
var ShowPager = { // 修改自 https://greasyfork.org/scripts/14178
|
||||
// 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
|
||||
var ShowPager = {
|
||||
getFullHref: function (e) {
|
||||
if(e == null) return '';
|
||||
"string" != typeof e && (e = e.getAttribute("href"));
|
||||
'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;
|
||||
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");
|
||||
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) {
|
||||
}
|
||||
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 (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();
|
||||
var r = document.createRange(),
|
||||
n = r.createContextualFragment(e);
|
||||
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);
|
||||
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的字符串");
|
||||
} 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}`);
|
||||
console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
|
||||
if(url === '') return;
|
||||
if(curSite.pageUrl === url) return;// 不会重复加载相同的页面
|
||||
curSite.pageUrl = url;
|
||||
@@ -516,45 +508,53 @@
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
function getElementByXpath(e, t, r) {
|
||||
r = r || document, t = t || r;
|
||||
function getElementByCSS(css, contextNode = document) {
|
||||
return contextNode.querySelector(css);
|
||||
}
|
||||
function getAllElementsByCSS(css, contextNode = document) {
|
||||
return [].slice.call(contextNode.querySelectorAll(css));
|
||||
}
|
||||
function getElementByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
try {
|
||||
return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
} catch (t) {
|
||||
return void console.error("无效的xpath");
|
||||
const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
||||
// 应该总是返回一个元素节点
|
||||
return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
|
||||
} catch (err) {
|
||||
throw new Error(`Invalid xpath: ${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);
|
||||
function getAllElementsByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
const result = [];
|
||||
try {
|
||||
const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
for (let i = 0; i < query.snapshotLength; i++) {
|
||||
const node = query.snapshotItem(i);
|
||||
// 如果是 Element 节点
|
||||
if (node.nodeType === 1) result.push(node);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`无效 Xpath: ${xpath}`);
|
||||
}
|
||||
|
||||
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 result;
|
||||
}
|
||||
function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
|
||||
if (!selector) return [];
|
||||
contextNode = contextNode || doc;
|
||||
if (typeof selector === 'string') {
|
||||
if (selector.search(/^css;/i) === 0) {
|
||||
return getAllElementsByCSS(selector.slice(4), contextNode);
|
||||
} else {
|
||||
return getAllElementsByXpath(selector, contextNode, doc);
|
||||
}
|
||||
} else {
|
||||
const query = selector(doc, win, _cplink);
|
||||
if (!Array.isArray(query)) {
|
||||
throw new Error('getAllElements 返回错误类型');
|
||||
} else {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
})();
|
||||
+89
-89
@@ -248,23 +248,6 @@
|
||||
}
|
||||
|
||||
|
||||
// 自动无缝翻页
|
||||
function pageLoading() {
|
||||
if (!menu_value('menu_pageLoading')) return
|
||||
if (curSite.SiteTypeID > 0){
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === "down") { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
|
||||
let scrollDelta = 666;
|
||||
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
|
||||
ShowPager.loadMorePage();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 回到顶部(右键点击空白处)
|
||||
function backToTop() {
|
||||
if (!menu_value('menu_backToTop')) return
|
||||
@@ -333,58 +316,67 @@
|
||||
}
|
||||
|
||||
|
||||
// 自动无缝翻页
|
||||
function pageLoading() {
|
||||
if (!menu_value('menu_pageLoading')) return
|
||||
if (curSite.SiteTypeID > 0){
|
||||
windowScroll(function (direction, e) {
|
||||
if (direction === 'down') { // 下滑才准备翻页
|
||||
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
|
||||
let scrollDelta = 666;
|
||||
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
|
||||
ShowPager.loadMorePage();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 滚动条事件
|
||||
function windowScroll(fn1) {
|
||||
var beforeScrollTop = document.documentElement.scrollTop,
|
||||
fn = fn1 || function () {};
|
||||
setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
|
||||
window.addEventListener("scroll", function (e) {
|
||||
window.addEventListener('scroll', function (e) {
|
||||
var afterScrollTop = document.documentElement.scrollTop,
|
||||
delta = afterScrollTop - beforeScrollTop;
|
||||
if (delta == 0) return false;
|
||||
fn(delta > 0 ? "down" : "up", e);
|
||||
fn(delta > 0 ? 'down' : 'up', e);
|
||||
beforeScrollTop = afterScrollTop;
|
||||
}, false);
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
|
||||
var ShowPager = { // 修改自 https://greasyfork.org/scripts/14178
|
||||
// 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
|
||||
var ShowPager = {
|
||||
getFullHref: function (e) {
|
||||
if(e == null) return '';
|
||||
"string" != typeof e && (e = e.getAttribute("href"));
|
||||
'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;
|
||||
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");
|
||||
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) {
|
||||
}
|
||||
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 (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();
|
||||
var r = document.createRange(),
|
||||
n = r.createContextualFragment(e);
|
||||
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);
|
||||
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的字符串");
|
||||
} else console.error('没有找到要转成 DOM 的字符串');
|
||||
},
|
||||
loadMorePage: function () {
|
||||
if (curSite.pager) {
|
||||
@@ -435,57 +427,65 @@
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
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 getElementByCSS(css, contextNode = document) {
|
||||
return contextNode.querySelector(css);
|
||||
}
|
||||
function getAllElementsByCSS(css, contextNode = document) {
|
||||
return [].slice.call(contextNode.querySelectorAll(css));
|
||||
}
|
||||
function getElementByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
try {
|
||||
const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
||||
// 应该总是返回一个元素节点
|
||||
return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
|
||||
} catch (err) {
|
||||
throw new Error(`Invalid xpath: ${xpath}`);
|
||||
}
|
||||
}
|
||||
function getAllElementsByXpath(xpath, contextNode, doc = document) {
|
||||
contextNode = contextNode || doc;
|
||||
const result = [];
|
||||
try {
|
||||
const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
for (let i = 0; i < query.snapshotLength; i++) {
|
||||
const node = query.snapshotItem(i);
|
||||
// 如果是 Element 节点
|
||||
if (node.nodeType === 1) result.push(node);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`无效 Xpath: ${xpath}`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
|
||||
if (!selector) return [];
|
||||
contextNode = contextNode || doc;
|
||||
if (typeof selector === 'string') {
|
||||
if (selector.search(/^css;/i) === 0) {
|
||||
return getAllElementsByCSS(selector.slice(4), contextNode);
|
||||
} else {
|
||||
return getAllElementsByXpath(selector, contextNode, doc);
|
||||
}
|
||||
} else {
|
||||
const query = selector(doc, win, _cplink);
|
||||
if (!Array.isArray(query)) {
|
||||
throw new Error('getAllElements 返回错误类型');
|
||||
} else {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
// 获取GET参数
|
||||
function getQueryVariable(variable) {
|
||||
var query = window.location.search.substring(1);
|
||||
var vars = query.split("&");
|
||||
for (var i=0;i<vars.length;i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if(pair[0] == variable){return pair[1];}
|
||||
}
|
||||
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);
|
||||
return(false);
|
||||
}
|
||||
})();
|
||||
|
||||
// 获取GET参数
|
||||
function getQueryVariable(variable)
|
||||
{
|
||||
var query = window.location.search.substring(1);
|
||||
var vars = query.split("&");
|
||||
for (var i=0;i<vars.length;i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if(pair[0] == variable){return pair[1];}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
Reference in New Issue
Block a user