优化 [自动更新外置翻页规则] 方式

This commit is contained in:
xiu2
2022-03-05 17:02:46 +08:00
parent e0e102b314
commit 23e1a96e49
+34 -23
View File
@@ -3,7 +3,7 @@
// @name:zh-CN 自动无缝翻页
// @name:zh-TW 自動無縫翻頁
// @name:en AutoPager
// @version 5.2.0
// @version 5.2.1
// @author X.I.U
// @description 无缝追加下一页内容(瀑布流),目前支持:【所有「Discuz!、Flarum、phpBB、Xiuno、XenForo、NexusPHP」论坛】【百度、谷歌(Google)、必应(Bing)、搜狗、微信、360、Yahoo、Yandex 等搜索引擎...】、贴吧、豆瓣、知乎、微博、NGA、V2EX、B 站(Bilibili)、煎蛋网、龙的天空、起点中文、IT之家、千图网、千库网、Pixabay、Pixiv、3DM、游侠网、游民星空、NexusMods、Steam 创意工坊、CS.RIN.RU、BT之家、萌番组、动漫花园、樱花动漫、爱恋动漫、AGE 动漫、Nyaa、SrkBT、RARBG、SubHD、423Down、不死鸟、扩展迷、小众软件、【动漫狂、漫画猫、漫画屋、漫画 DB、动漫之家、拷贝漫画、HiComic、Mangabz、Xmanhua 等漫画网站...】、PubMed、Z-Library、GreasyFork、Github、StackOverflow(以上仅一小部分,更多的写不下了...
// @description:zh-TW 無縫追加下一頁內容(瀑布流),支持各論壇、社交、遊戲、漫畫、小說、學術、搜索引擎(Google、Bing、Yahoo...) 等網站~
@@ -1367,37 +1367,48 @@ function: {
}
// 获取外置翻页规则
function getRulesUrl(update = false) {
if (GM_getValue('menu_ruleUpdateTime') == null) update = true
if (update) GM_setValue('menu_ruleUpdateTime', '1970/1/1');
//console.log(new Date().getTime());
let timeNow = new Date().getFullYear() + '/' + (new Date().getMonth() + 1) + '/' + new Date().getDate(),
timeOld = GM_getValue('menu_ruleUpdateTime');
if (!timeOld || timeOld != timeNow) { // 是新的一天
GM_setValue('menu_ruleUpdateTime', timeNow); // 写入时间以供后续比较
// 如果是原来的时间格式 或 刚安装脚本,则需要立即更新
if (typeof(GM_getValue('menu_ruleUpdateTime', '')) == 'string') update = true
if (update) { // 手动更新(或安装后首次更新)
GM_setValue('menu_ruleUpdateTime', parseInt(+new Date()/1000)); // 写入当前时间戳
getRulesUrl_(update, true); // 立即更新规则
} else { // 自动更新
if (parseInt(+new Date()/1000) - GM_getValue('menu_ruleUpdateTime', 0) > 86400) getRulesUrl_(); // 距离上次检查更新超过 1 天,则对比远程时间戳
}
function getRulesUrl_(update = false, notification = false) {
GM_xmlhttpRequest({
url: 'https://userscript.xiu2.xyz/other/Autopage/rules.json',
url: (update === true) ? 'https://userscript.xiu2.xyz/other/Autopage/rules.json' : 'https://userscript.xiu2.xyz/other/Autopage/ruleUpdateTime.json',
method: 'GET',
responseType: 'json',
overrideMimeType: 'application/json; charset=utf-8',
responseType: (update === true) ? 'json' : 'text',
overrideMimeType: (update === true) ? 'application/json; charset=utf-8' : 'text/plain; charset=utf-8',
timeout: 5000,
onload: function (response) {
try {
//console.log('最终 URL' + response.finalUrl, '返回内容:',response.response)
if (response.response) {
GM_setValue('menu_rules', response.response);
if (update) {
curSite = {SiteTypeID: 0}; pageNum.now = 1; // 重置规则+页码
registerMenuCommand(); // 重新判断规则
//console.log(new Date().getTime());
//console.log(curSite);
if (curSite.style) {insStyle(curSite.style)} // 插入 Style CSS 样式
curSite.pageUrl = ''; // 下一页URL
pageLoading(); // 自动无缝翻页
if (GM_getValue('menu_page_number')) {pageNumber('add');} else {pageNumber('set');} // 显示页码
pausePageEvent(); // 左键双击网页空白处暂停翻页
GM_notification({text: '✅ 已更新外置翻页规则!\n如果依然无法翻页,则说明还不支持当前网页,欢迎点击此处提交申请~', timeout: 5000, onclick: 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});}});
if (!update) { // 获取远程时间戳并对比
if (parseInt(response.response) && parseInt(response.response) > GM_getValue('menu_ruleUpdateTime', 0)) {
GM_setValue('menu_ruleUpdateTime', parseInt(+new Date()/1000)); // 写入当前时间戳
getRulesUrl_(true);
} else {GM_setValue('menu_ruleUpdateTime', parseInt(+new Date()/1000));}
} else { // 写入最新规则
GM_setValue('menu_rules', response.response);
if (notification) { // 通知并重新判断
curSite = {SiteTypeID: 0}; pageNum.now = 1; // 重置规则+页码
registerMenuCommand(); // 重新判断规则
if (curSite.style) {insStyle(curSite.style)} // 插入 Style CSS 样式
curSite.pageUrl = ''; // 下一页URL
pageLoading(); // 自动无缝翻页
if (GM_getValue('menu_page_number')) {pageNumber('add');} else {pageNumber('set');} // 显示页码
pausePageEvent(); // 左键双击网页空白处暂停翻页
GM_notification({text: '✅ 已更新外置翻页规则!\n如果依然无法翻页,则说明还不支持当前网页,欢迎点击此处提交申请~', timeout: 5000, onclick: 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});}});
}
}
} else {
GM_notification({text: '❌ 更新失败,请联系作者解决...', timeout: 5000});