优化 [自定义翻页规则] 功能 (支持域名使用正则)

This commit is contained in:
xiu2
2022-02-22 17:12:34 +08:00
parent 349efb4f2d
commit e1cadebdd4
+21 -18
View File
@@ -3,7 +3,7 @@
// @name:zh-CN 自动无缝翻页
// @name:zh-TW 自動無縫翻頁
// @name:en AutoPager
// @version 4.8.8
// @version 4.9.0
// @author X.I.U
// @description 无缝拼接下一页内容(瀑布流,追求小而美),目前支持:【所有「Discuz!、Flarum、phpBB、Xiuno、XenForo、NexusPHP」论坛】【百度、谷歌、必应、搜狗、微信、360、Yahoo、Yandex 等搜索引擎】、贴吧、豆瓣、知乎、微博、NGA、V2EX、B 站(Bilibili)、煎蛋网、糗事百科、龙的天空、起点中文、IT之家、千图网、Pixabay、Pixiv、3DM、游侠网、游民星空、NexusMods、Steam 创意工坊、CS.RIN.RU、BT之家、萌番组、动漫花园、樱花动漫、爱恋动漫、AGE 动漫、Nyaa、SrkBT、RARBG、SubHD、423Down、不死鸟、扩展迷、小众软件、【动漫狂、漫画猫、漫画屋、漫画 DB、动漫之家、拷贝漫画、包子漫画、Mangabz、Xmanhua 等漫画网站】、PubMed、Z-Library、GreasyFork、Github、StackOverflow(以上仅一小部分,更多的写不下了...
// @description:zh-TW 無縫拼接下一頁內容(瀑布流,追求小而美),支持各種論壇、搜索引擎、漫畫網站~
@@ -1181,6 +1181,8 @@
if (Array.isArray(DBSite[now].host)) {
for (let i of DBSite[now].host) { // 遍历 数组
// 针对自定义翻页规则中的正则
if (typeof i === 'string' && i.slice(0,1) === '/') i = new RegExp(i.slice(1,i.length-1))
if ((i instanceof RegExp && i.test(location.hostname)) || (typeof i === 'string' && i === location.hostname)) {
if (self != top) {if (!DBSite[now].iframe) break end;} // 如果当前位于 iframe 框架下,就需要判断是否需要继续执行
@@ -1197,22 +1199,25 @@
}
}
// 如果是 正则/字符串
} else if ((DBSite[now].host instanceof RegExp && DBSite[now].host.test(location.hostname)) || (typeof DBSite[now].host === 'string' && DBSite[now].host === location.hostname)) {
// 如果是 正则/字符串
} else {
// 针对自定义翻页规则中的正则
if (typeof DBSite[now].host === 'string' && DBSite[now].host.slice(0,1) === '/') DBSite[now].host = new RegExp(DBSite[now].host.slice(1,DBSite[now].host.length-1))
if ((DBSite[now].host instanceof RegExp && DBSite[now].host.test(location.hostname)) || (typeof DBSite[now].host === 'string' && DBSite[now].host === location.hostname)) {
if (self != top) {if (!DBSite[now].iframe) break;} // 如果当前位于 iframe 框架下,就需要判断是否需要继续执行
if (DBSite[now].functionS) {
if (typeof DBSite[now].functionS == 'function') {
DBSite[now].functionS();
} else { // 自定义翻页规则时
if (new Function (DBSite[now].functionS)() === true) curSite = DBSite[now];
if (self != top) {if (!DBSite[now].iframe) break;} // 如果当前位于 iframe 框架下,就需要判断是否需要继续执行
if (DBSite[now].functionS) {
if (typeof DBSite[now].functionS == 'function') {
DBSite[now].functionS();
} else { // 自定义翻页规则时
if (new Function (DBSite[now].functionS)() === true) curSite = DBSite[now];
}
} else {
curSite = DBSite[now];
}
} else {
curSite = DBSite[now];
support = true; break; // 如果找到了就退出循环
}
support = true; break; // 如果找到了就退出循环
}
}
if (support) {
@@ -1298,7 +1303,7 @@
pager: {
type: 翻页模式
1 = 由脚本实现自动无缝翻页适用于静态加载内容网站常规模式
1 = 由脚本实现自动无缝翻页可省略适用于静态加载内容网站常规模式
2 = 只需要点击下一页按钮适用于网站自带了 自动无缝翻页 功能
nextText: 按钮文本当按钮文本 = 该文本时才会点击按钮加载下一页避免一瞬间加载太多次下一页下同
@@ -7714,17 +7719,16 @@ function: {
<h1><strong>自定义翻页规则优先于脚本内置规则</strong></h1>
<ul style="list-style: disc !important; margin-left: 35px !important;">
<li>翻页规则为 JSON 格式因此大家需要先去了解一下 JSON 的基本格式两边都需要双引号最后一个末尾不能加逗号等</li>
<li>具体的翻页规则说明示例为了方便更新及补充我都写到 <a href="https://greasyfork.org/scripts/419215" target="_blank">Greasyfork</a> 及 <a href="https://github.com/XIU2/UserScript/issues/176" target="_blank">Github</a> </li>
<li>具体的翻页规则说明示例为了方便更新及补充我都写到 <a href="https://github.com/XIU2/UserScript/issues/176" target="_blank">Github</a> 及 <a href="https://greasyfork.org/scripts/419215" target="_blank">Greasyfork</a> </li>
<li>该脚本最初只是自用的没有考虑到自定义翻页规则因此我只能勉强实现该功能但局限性比较多只适用于简单的网站</li>
<li>脚本会自动格式化规则因此无需手动缩进换行</li>
</ul>
<p style="color: #ff3535 !important;">注意不要完全照搬脚本内置规则因为和标准 JSON 格式有所差别必须两边内容都加双引号不能用单引号</p>
<textarea id="Autopage_customRules_textarea" style="min-width:50% !important; min-height:200px !important; display: block !important; margin: 10px 0 10px 0;" placeholder="啊啊啊啊&#13;&#10;呃呃呃呃">${JSON.stringify(GM_getValue('menu_customRules', {}), null, '\t')}</textarea>
<textarea id="Autopage_customRules_textarea" style="min-width:50% !important; min-height:200px !important; display: block !important; margin: 10px 0 10px 0;" placeholder="留空等于默认的 {}">${JSON.stringify(GM_getValue('menu_customRules', {}), null, '\t')}</textarea>
<button id="Autopage_customRules_save">保存并刷新</button><button id="Autopage_customRules_cancel"></button>
</div>`
document.documentElement.insertAdjacentHTML('beforeend', _html);
if (curSite.pager && curSite.pager.type == 5) window.top.document.xiu_pausePage = pausePage
// 点击事件
getCSS('#Autopage_customRules_save').onclick = function () {
let rules = getCSS('#Autopage_customRules_textarea').value;
@@ -7741,7 +7745,6 @@ function: {
}
}
getCSS('#Autopage_customRules_cancel').onclick = function () {getCSS('#Autopage_customRules').remove();}
//status = getCSS('#Autopage_customRules');
}
// 显示页码
function pageNumber(type) {