Skip to content

Commit 40261f4

Browse files
committed
新增 [423Down 增强] 脚本(自动无缝翻页)
1 parent 6a6c502 commit 40261f4

3 files changed

Lines changed: 205 additions & 1 deletion

File tree

423Down-Enhanced.user.js

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// ==UserScript==
2+
// @name 423Down 增强
3+
// @version 1.0.0
4+
// @author X.I.U
5+
// @description 自动无缝翻页
6+
// @match *://www.423down.com/*
7+
// @exclude *://www.423down.com/*.html
8+
// @icon https://www.423down.com/favicon.ico
9+
// @grant GM_xmlhttpRequest
10+
// @grant GM_registerMenuCommand
11+
// @license GPL-3.0 License
12+
// @run-at document-end
13+
// @namespace https://github.com/XIU2/UserScript
14+
// ==/UserScript==
15+
16+
(function() {
17+
// 注册脚本菜单
18+
GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript', {active: true,insert: true,setParent: true});});
19+
20+
// 默认 ID 为 0
21+
var curSite = {SiteTypeID: 0};
22+
23+
// 自动翻页规则
24+
let DBSite = {
25+
postslist: {
26+
SiteTypeID: 1,
27+
pager: {
28+
nextLink: '//div[@class="paging"]//a[contains(text(),"下一页")][@href]',
29+
pageElement: 'css;div.content-wrap ul.excerpt > li',
30+
HT_insert: ['css;div.content-wrap ul.excerpt', 2],
31+
replaceE: 'css;div.paging',
32+
}
33+
}
34+
};
35+
36+
// 用于脚本内部判断当前 URL 类型
37+
let SiteType = {
38+
POSTSLIST: DBSite.postslist.SiteTypeID
39+
};
40+
41+
curSite = DBSite.postslist;
42+
curSite.pageUrl = ""; // 下一页URL
43+
pageLoading(); // 自动翻页
44+
45+
46+
// 自动翻页
47+
function pageLoading() {
48+
if (curSite.SiteTypeID > 0){
49+
windowScroll(function (direction, e) {
50+
if (direction === "down") { // 下滑才准备翻页
51+
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
52+
let scrollDelta = 1299;
53+
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
54+
ShowPager.loadMorePage();
55+
}
56+
}
57+
});
58+
}
59+
}
60+
61+
62+
// 滚动条事件
63+
function windowScroll(fn1) {
64+
var beforeScrollTop = document.documentElement.scrollTop,
65+
fn = fn1 || function () {};
66+
setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
67+
window.addEventListener("scroll", function (e) {
68+
var afterScrollTop = document.documentElement.scrollTop,
69+
delta = afterScrollTop - beforeScrollTop;
70+
if (delta == 0) return false;
71+
fn(delta > 0 ? "down" : "up", e);
72+
beforeScrollTop = afterScrollTop;
73+
}, false);
74+
}, 1000)
75+
}
76+
77+
78+
var ShowPager = { // 修改自 https://greasyfork.org/scripts/14178
79+
getFullHref: function (e) {
80+
if(e == null) return '';
81+
"string" != typeof e && (e = e.getAttribute("href"));
82+
var t = this.getFullHref.a;
83+
return t || (this.getFullHref.a = t = document.createElement("a")), t.href = e, t.href;
84+
},
85+
createDocumentByString: function (e) {
86+
if (e) {
87+
if ("HTML" !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, "application/xhtml+xml");
88+
var t;
89+
try {
90+
t = (new DOMParser).parseFromString(e, "text/html");
91+
} catch (e) {
92+
}
93+
if (t) return t;
94+
if (document.implementation.createHTMLDocument) t = document.implementation.createHTMLDocument("ADocument"); else try {
95+
(t = document.cloneNode(!1)).appendChild(t.importNode(document.documentElement, !1)),
96+
t.documentElement.appendChild(t.createElement("head")), t.documentElement.appendChild(t.createElement("body"));
97+
} catch (e) {
98+
}
99+
if (t) {
100+
var r = document.createRange();
101+
r.selectNodeContents(document.body);
102+
var n = r.createContextualFragment(e);
103+
t.body.appendChild(n);
104+
for (var a, o = {
105+
TITLE: !0,
106+
META: !0,
107+
LINK: !0,
108+
STYLE: !0,
109+
BASE: !0
110+
}, i = t.body, s = i.childNodes, c = s.length - 1; c >= 0; c--) o[(a = s[c]).nodeName] && i.removeChild(a);
111+
return t;
112+
}
113+
} else console.error("没有找到要转成DOM的字符串");
114+
},
115+
loadMorePage: function () {
116+
if (curSite.pager) {
117+
let curPageEle = getElementByXpath(curSite.pager.nextLink);
118+
var url = this.getFullHref(curPageEle);
119+
//console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
120+
if(url === '') return;
121+
if(curSite.pageUrl === url) return;// 不会重复加载相同的页面
122+
curSite.pageUrl = url;
123+
// 读取下一页的数据
124+
curSite.pager.startFilter && curSite.pager.startFilter();
125+
GM_xmlhttpRequest({
126+
url: url,
127+
method: "GET",
128+
timeout: 5000,
129+
onload: function (response) {
130+
try {
131+
var newBody = ShowPager.createDocumentByString(response.responseText);
132+
let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody);
133+
let toElement = getAllElements(curSite.pager.HT_insert[0])[0];
134+
if (pageElems.length >= 0) {
135+
let addTo = "beforeend";
136+
if (curSite.pager.HT_insert[1] == 1) addTo = "beforebegin";
137+
// 插入新页面元素
138+
pageElems.forEach(function (one) {
139+
toElement.insertAdjacentElement(addTo, one);
140+
});
141+
// 替换待替换元素
142+
try {
143+
let oriE = getAllElements(curSite.pager.replaceE);
144+
let repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
145+
if (oriE.length === repE.length) {
146+
for (var i = 0; i < oriE.length; i++) {
147+
oriE[i].outerHTML = repE[i].outerHTML;
148+
}
149+
}
150+
} catch (e) {
151+
console.log(e);
152+
}
153+
}
154+
} catch (e) {
155+
console.log(e);
156+
}
157+
}
158+
});
159+
}
160+
},
161+
};
162+
163+
164+
function getElementByXpath(e, t, r) {
165+
r = r || document, t = t || r;
166+
try {
167+
return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
168+
} catch (t) {
169+
return void console.error("无效的xpath");
170+
}
171+
}
172+
173+
174+
function getAllElements(e, t, r, n, o) {
175+
let getAllElementsByXpath = function(e, t, r) {
176+
return r = r || document, t = t || r, r.evaluate(e, t, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
177+
}
178+
179+
var i, s = [];
180+
if (!e) return s;
181+
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) {
182+
return (t || document).querySelectorAll(e);
183+
}(e.slice(4), t) : getAllElementsByXpath(e, t, r); else {
184+
if (!(i = e(r, n, o))) return s;
185+
if (i.nodeType) return s[0] = i, s;
186+
}
187+
return function makeArray(e) {
188+
var t, r, n, o = [];
189+
if (e.pop) {
190+
for (t = 0, r = e.length; t < r; t++) (n = e[t]) && (n.nodeType ? o.push(n) : o = o.concat(makeArray(n)));
191+
return a()(o);
192+
}
193+
if (e.item) {
194+
for (t = e.length; t;) o[--t] = e[t];
195+
return o;
196+
}
197+
if (e.iterateNext) {
198+
for (t = e.snapshotLength; t;) o[--t] = e.snapshotItem(t);
199+
return o;
200+
}
201+
}(i);
202+
}
203+
})();

GoogleTranslate-Beautification.user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// @grant GM_notification
1515
// @license GPL-3.0 License
1616
// @run-at document-start
17-
// @namespace https://github.com/XIU2/UserScript
17+
// @namespace https://greasyfork.org/scripts/413721
1818
// ==/UserScript==
1919

2020
(function() {

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| **Github 增强** | 高速下载 Clone、Release、Raw、Code(ZIP) 文件... | **[「安装」](https://greasyfork.org/scripts/412245)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/GithubEnhanced-High-Speed-Download.user.js)** |
2121
| **3DM论坛 美化** | 精简多余内容 | **[「安装」](https://greasyfork.org/scripts/413593)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/3dm-Beautification.user.js)** |
2222
| **3DM论坛 增强** | 自动回复、自动无缝翻页、清理置顶帖子 | **[「安装」](https://greasyfork.org/scripts/412890)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/3dm-Enhanced.user.js)** |
23+
| **423Down 增强 \*** | 自动无缝翻页 | **[「安装」](https://greasyfork.org/scripts/419215)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/423Down-Enhanced.user.js)** |
2324
| **智友邦论坛 美化** | 精简多余内容、宽屏显示 | **[「安装」](https://greasyfork.org/scripts/412361)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/Zhiyoo-Beautification.user.js)** |
2425
| **智友邦论坛 增强** | 自动签到、自动回复、自动无缝翻页、清理置顶帖子... | **[「安装」](https://greasyfork.org/scripts/412362)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/Zhiyoo-Enhanced.user.js)** |
2526
| ~~_**Google 翻译 美化**_~~ | ~~_精简多余内容、修复翻译结果溢出屏幕问题_~~ | ~~_**[「安装」](https://greasyfork.org/scripts/413721)**_~~ | ~~_**[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/GoogleTranslate-Beautification.user.js)**_~~ |

0 commit comments

Comments
 (0)