Skip to content

Commit aeb4d29

Browse files
committed
新增 [显示当前页面(左下角)] 功能
1 parent 5b8e55c commit aeb4d29

1 file changed

Lines changed: 110 additions & 24 deletions

File tree

Autopage.user.js

Lines changed: 110 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// ==UserScript==
22
// @name 自动无缝翻页
3-
// @version 1.8.8
3+
// @version 1.8.9
44
// @author X.I.U
55
// @description 无缝拼接下一页内容,目前支持:[所有使用「Discuz!、Flarum、DUX(WordPress)」的网站]、百度、谷歌、必应、贴吧、豆瓣、微博、NGA(玩家社区)、V2EX、超能网、IT之家、千图网、Pixabay、3DM、游侠网、游民星空、NexusMods、Steam 创意工坊、小霸王其乐无穷、茶杯狐、NO视频、低端影视、奈菲影视、91美剧网、真不卡影院、片库、音范丝、BT之家、爱恋动漫、Nyaa、SrkBT、RARBG、423Down、不死鸟、小众软件、极简插件、果核剥壳、六音软件、微当下载、th-sjy 汉化、异次元软件、老殁殁漂遥、异星软件空间、动漫狂、漫画DB、HiComic(嗨漫画)、古风漫画网、砂之船动漫家、PubMed、wikiHow、GreasyFork、CS.RIN.RU、FitGirl...
66
// @match *://*/*
77
// @connect www.gamersky.com
88
// @icon https://i.loli.net/2021/03/07/rdijeYm83pznxWq.png
99
// @grant GM_xmlhttpRequest
1010
// @grant GM_registerMenuCommand
11+
// @grant GM_unregisterMenuCommand
1112
// @grant GM_openInTab
1213
// @grant GM_getValue
1314
// @grant GM_setValue
@@ -23,26 +24,53 @@
2324

2425
(function() {
2526
'use strict';
26-
var webType = 0, curSite = {SiteTypeID: 0}, DBSite, SiteType, pausePage = true;
27-
if (GM_getValue('menu_disable') == null){GM_setValue('menu_disable', [])}; if (GM_getValue('menu_discuz_thread_page') == null){GM_setValue('menu_discuz_thread_page', true)}; if (GM_getValue('menu_pause_page') == null){GM_setValue('menu_pause_page', true)};
27+
var menuAll = [
28+
['menu_disable', '✅ 已启用 (点击对当前网站禁用)', '❌ 已禁用 (点击对当前网站启用)', []],
29+
['menu_discuz_thread_page', '帖子内自动翻页 (仅论坛)', '帖子内自动翻页 (仅论坛)', true],
30+
['menu_pause_page', '左键双击网页空白处暂停翻页', '左键双击网页空白处暂停翻页', true],
31+
['menu_page_number', '显示当前页码 (左下角)', '显示当前页码 (左下角)', true]
32+
], menuId = [], webType = 0, curSite = {SiteTypeID: 0}, DBSite, SiteType, pausePage = true, pageNum = {now: 1, _now: 1};
33+
for (let i=0;i<menuAll.length;i++){ // 如果读取到的值为 null 就写入默认值
34+
if (GM_getValue(menuAll[i][0]) == null){GM_setValue(menuAll[i][0], menuAll[i][3])};
35+
}
36+
registerMenuCommand();
37+
if (menuId.length < 2) {return}
2838
// 注册脚本菜单
29-
if (menu_disable('check')) { // 当前网站是否已存在禁用列表中
30-
GM_registerMenuCommand('❌ 已禁用 (点击对当前网站启用)', function(){menu_disable('del')});
31-
return
32-
} else {
33-
webType = doesItSupport(); // 判断网站类型(即是否支持),顺便直接赋值
34-
if (webType === 0) {
35-
GM_registerMenuCommand('❌ 当前网站暂不支持 [点击申请支持]', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/419215/feedback', {active: true,insert: true,setParent: true});});
36-
console.info('[自动无缝翻页] - 不支持当前网站,欢迎申请支持:https://github.com/XIU2/UserScript / https://greasyfork.org/zh-CN/scripts/419215/feedback');
37-
return
39+
function registerMenuCommand() {
40+
if (menuId.length != []){
41+
for (let i=0;i<menuId.length;i++){
42+
GM_unregisterMenuCommand(menuId[i]);
43+
}
3844
}
39-
GM_registerMenuCommand('✅ 已启用 (点击对当前网站禁用)', function(){menu_disable('add')});
40-
if (webType === 2 || location.host === 'cs.rin.ru') {
41-
GM_registerMenuCommand(`${GM_getValue('menu_discuz_thread_page')?'✅':'❌'} 帖子内自动翻页 (仅论坛)`, function(){menu_switch(GM_getValue('menu_discuz_thread_page'), 'menu_discuz_thread_page', 'Discuz! 论坛帖子内翻页')});
45+
for (let i=0;i<menuAll.length;i++) { // 循环注册脚本菜单
46+
menuAll[i][3] = GM_getValue(menuAll[i][0]);
47+
if (menuAll[i][0] === 'menu_disable') { // 启用/禁用
48+
49+
if (menu_disable('check')) { // 当前网站在禁用列表中
50+
menuId[i] = GM_registerMenuCommand(`${menuAll[i][2]}`, function(){menu_disable('del')});
51+
return
52+
} else { // // 不在禁用列表中
53+
webType = doesItSupport(); // 判断网站类型(即是否支持),顺便直接赋值
54+
if (webType === 0) {
55+
GM_registerMenuCommand('❌ 当前网站暂不支持 [点击申请支持]', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/419215/feedback', {active: true,insert: true,setParent: true});});
56+
console.info('[自动无缝翻页] - 不支持当前网站,欢迎申请支持:https://github.com/XIU2/UserScript / https://greasyfork.org/zh-CN/scripts/419215/feedback');
57+
return
58+
}
59+
menuId[i] = GM_registerMenuCommand(`${menuAll[i][1]}`, function(){menu_disable('add')});
60+
}
61+
62+
} else if (menuAll[i][0] === 'menu_discuz_thread_page') { // 帖子内自动翻页 (仅论坛)
63+
64+
if (webType === 2 || location.host === 'cs.rin.ru') {
65+
menuId[i] = GM_registerMenuCommand(`${menuAll[i][3]?'✅':'❌'} ${menuAll[i][1]}`, function(){menu_switch(menuAll[i][3], menuAll[i][0], menuAll[i][2])});
66+
}
67+
68+
} else {
69+
menuId[i] = GM_registerMenuCommand(`${menuAll[i][3]?'✅':'❌'} ${menuAll[i][1]}`, function(){menu_switch(menuAll[i][3], menuAll[i][0], menuAll[i][2])});
70+
}
4271
}
43-
GM_registerMenuCommand(`${GM_getValue('menu_pause_page')?'✅':'❌'} 左键双击网页空白处暂停翻页`, function(){menu_switch(GM_getValue('menu_pause_page'), 'menu_pause_page', '左键双击网页空白处暂停翻页')});
72+
menuId[menuId.length] = GM_registerMenuCommand('💬 反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/412212/feedback', {active: true,insert: true,setParent: true});});
4473
}
45-
GM_registerMenuCommand('💬 反馈 & 欢迎申请支持', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/419215/feedback', {active: true,insert: true,setParent: true});});
4674

4775
function setDBSite() {
4876
/*
@@ -1522,6 +1550,7 @@
15221550
}
15231551
}
15241552

1553+
if (GM_getValue('menu_page_number')) {pageNumber('add');} else {pageNumber('set');} // 显示页码
15251554
pausePageEvent(); // 左键双击网页空白处暂停翻页
15261555
curSite.pageUrl = ''; // 下一页URL
15271556
//console.log(curSite);
@@ -1621,6 +1650,8 @@
16211650
var temp_baidu_tieba = document.createElement('div'); temp_baidu_tieba.innerHTML = scriptJSON; // 字符串转 Element 元素
16221651
pageElems = curSite.function.before(getAllElements(curSite.pager.pageElement, temp_baidu_tieba, temp_baidu_tieba)); // 插入前执行函数
16231652
pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);}); // 插入元素
1653+
// 当前页码 + 1
1654+
pageNum.now = pageNum._now + 1
16241655
// 替换元素
16251656
let oriE = document.querySelectorAll(curSite.pager.pageElement.replace('css;', '')),
16261657
repE = getAllElements(curSite.pager.replaceE, temp_baidu_tieba, temp_baidu_tieba);
@@ -1733,6 +1764,8 @@
17331764
});
17341765
// 插入网页
17351766
pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);});
1767+
// 当前页码 + 1
1768+
pageNum.now = pageNum._now + 1
17361769
// 替换元素
17371770
let oriE = document.querySelectorAll(curSite.pager.replaceE.replace('css;', '')),
17381771
repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
@@ -1869,6 +1902,8 @@
18691902
for (let i = 0; i < oriE.length; i++) {
18701903
oriE[i].outerHTML = repE[i].outerHTML;
18711904
}
1905+
// 当前页码 + 1
1906+
pageNum.now = pageNum._now + 1
18721907
manhuadb_init(); // 将刚刚替换的图片插入网页中
18731908
}
18741909
}
@@ -1914,6 +1949,8 @@
19141949
_img += `<img src="${src}">`
19151950
}
19161951
document.querySelector(curSite.pager.insertPosition[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.insertPosition[1]), _img); // 将 img 标签插入到网页中
1952+
// 当前页码 + 1
1953+
pageNum.now = pageNum._now + 1
19171954
}
19181955

19191956

@@ -1964,6 +2001,8 @@
19642001
_img += '<img src="https://res.xiaoqinre.com/' + chapterPath + one2 + '" data-index="0" style="display: inline-block;">'
19652002
})
19662003
document.querySelector(curSite.pager.insertPosition[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.insertPosition[1]), _img); // 将 img 标签插入到网页中
2004+
// 当前页码 + 1
2005+
pageNum.now = pageNum._now + 1
19672006
}
19682007
}
19692008
}
@@ -2012,13 +2051,13 @@
20122051
if (autopbn) { // 寻找下一页链接
20132052
// 避免重复点击翻页按钮
20142053
if (curSite.pager.nextText) { // 按钮文本,当按钮文本 = 该文本时,才会点击按钮加载下一页
2015-
if (autopbn.innerText === curSite.pager.nextText) autopbn.click();
2054+
if (autopbn.innerText === curSite.pager.nextText) {autopbn.click(); pageNum.now = pageNum._now + 1;} // 当前页码 + 1
20162055
} else if (curSite.pager.nextTextOf) { // 按钮文本的一部分,当按钮文本包含该文本时,才会点击按钮加载下一页
2017-
if (autopbn.innerText.indexOf(curSite.pager.nextTextOf) > -1) autopbn.click();
2056+
if (autopbn.innerText.indexOf(curSite.pager.nextTextOf) > -1) {autopbn.click(); pageNum.now = pageNum._now + 1;} // 当前页码 + 1
20182057
} else if (curSite.pager.nextHTML) { // 按钮内元素,当按钮内元素 = 该元素内容时,才会点击按钮加载下一页
2019-
if (autopbn.innerHTML === curSite.pager.nextHTML) autopbn.click();
2058+
if (autopbn.innerHTML === curSite.pager.nextHTML) {autopbn.click(); pageNum.now = pageNum._now + 1;} // 当前页码 + 1
20202059
} else { // 如果没有指定按钮文字就直接点击
2021-
autopbn.click();
2060+
autopbn.click(); pageNum.now = pageNum._now + 1; // 当前页码 + 1
20222061
// 对于没有按钮文字变化的按钮,可以手动指定间隔时间
20232062
if (curSite.pager.intervals) {
20242063
let _SiteTypeID = curSite.SiteTypeID; curSite.SiteTypeID = 0;
@@ -2102,14 +2141,58 @@
21022141
}
21032142

21042143

2144+
// 显示页码
2145+
function pageNumber(type) {
2146+
if (curSite.SiteTypeID === 0) return
2147+
let status = document.getElementById('Autopage_number');
2148+
switch (type) {
2149+
case 'add':
2150+
add(); break;
2151+
case 'del':
2152+
del(); break;
2153+
case 'set':
2154+
set(); break;
2155+
}
2156+
2157+
function add(){
2158+
if (status) {
2159+
if (status.style.display === 'none') {status.style.display = 'flex';}
2160+
return
2161+
}
2162+
// 插入网页
2163+
let _html = `<style>#Autopage_number {top: calc(75vh) !important;left: 0 !important;width: 32px;height: 32px;padding: 6px !important;display: flex;position: fixed !important;opacity: 0.5;transition: .2s;z-index: 1000 !important;cursor: pointer;user-select: none !important;flex-direction: column;align-items: center;justify-content: center;box-sizing: content-box;border-radius: 0 50% 50% 0;transform-origin: center !important;transform: translateX(-8px);background-color: #eeec;-webkit-tap-highlight-color: transparent;box-shadow: 1px 1px 3px 0px #989898 !important;color: #000 !important;} #Autopage_number:hover {opacity: 1;transform: translateX(0);}</style>
2164+
<div id="Autopage_number" title="当前页码&#10;&#10;(可在 [自动无缝翻页] 脚本菜单中关闭)">${pageNum._now}</div>`
2165+
document.body.insertAdjacentHTML('beforeend', _html);
2166+
set();
2167+
}
2168+
// 监听储存当前页码的对象值的变化
2169+
function set(){
2170+
Object.defineProperty(pageNum, 'now', {
2171+
set: function(value) {
2172+
this._now = value;
2173+
document.getElementById('Autopage_number').textContent = value;
2174+
}
2175+
});
2176+
}
2177+
function del(){
2178+
if (!status) return
2179+
status.style.display = 'none';
2180+
}
2181+
}
2182+
2183+
21052184
// 菜单开关
21062185
function menu_switch(menu_status, Name, Tips) {
21072186
if (menu_status === true){
2108-
GM_setValue(`${Name}`, false);
2187+
GM_setValue(Name, false);
21092188
} else {
2110-
GM_setValue(`${Name}`, true);
2189+
GM_setValue(Name, true);
21112190
}
2112-
location.reload();
2191+
if (Name === 'menu_page_number') {
2192+
if (menu_status === true){pageNumber('del');} else {pageNumber('add');}
2193+
registerMenuCommand(); // 重新注册脚本菜单
2194+
} else {
2195+
location.reload();}
21132196
};
21142197

21152198

@@ -2316,6 +2399,9 @@
23162399
// 插入新页面元素
23172400
pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);});
23182401

2402+
// 当前页码 + 1
2403+
pageNum.now = pageNum._now + 1
2404+
23192405
// 插入 <script> 标签
23202406
if (curSite.pager.scriptType) {
23212407
let scriptText = '';

0 commit comments

Comments
 (0)