Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 44 additions & 17 deletions Autopage.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @name:zh-CN 自动无缝翻页
// @name:zh-TW 自動無縫翻頁
// @name:en AutoPager
// @version 6.4.25
// @version 6.4.26
// @author X.I.U
// @description ⭐无缝加载 下一页内容 至网页底部(类似瀑布流)⭐,目前支持:【所有「Discuz!、Flarum、phpBB、Xiuno、XenForo、NexusPHP...」论坛】【百度、谷歌(Google)、必应(Bing)、搜狗、微信、360、Yahoo、Yandex 等搜索引擎...】、贴吧、豆瓣、知乎、B 站(bilibili)、NGA、V2EX、煎蛋网、龙的天空、起点中文、千图网、千库网、Pixabay、Pixiv、3DM、游侠网、游民星空、NexusMods、Steam 创意工坊、CS.RIN.RU、RuTracker、BT之家、萌番组、动漫花园、樱花动漫、爱恋动漫、AGE 动漫、Nyaa、SrkBT、RARBG、SubHD、423Down、不死鸟、扩展迷、小众软件、【动漫狂、动漫屋、漫画猫、漫画屋、漫画 DB、动漫之家、HiComic、Mangabz、Xmanhua 等漫画网站...】、PubMed、Z-Library、GreasyFork、Github、StackOverflow(以上仅一小部分,更多的写不下了...
// @description:zh-TW ⭐無縫加載 下一頁內容 至網頁底部(類似瀑布流)⭐,支持各論壇、社交、遊戲、漫畫、小說、學術、搜索引擎(Google、Bing、Yahoo...) 等網站~
Expand Down Expand Up @@ -495,7 +495,7 @@ pager: {
当 pageE: '.item' 且 insertP: ['.page', 1] 时,实际等同于 ['.item', 5]
注意:如 pageE 中选择了多类元素,则不能省略 insertP(比如包含 `,` 与 `|` 符号),除非另外的选择器是 <script> <style> <link> 标签

replaceE: 要替换为下一页内容的元素(比如页码),省略后默认替换 nextL 元素(仅限模式1/3/6,且 js 代码除外),值为空 "" 时则完全不替换
replaceE: 要替换为下一页内容的元素(比如页码),省略后将会自动判断是替换 nextL 元素还是 nextL 的父元素(当 nextL 元素后面或前面有 <a> 的相邻兄弟元素时替换其父元素,反之替换其自身,仅限模式1/3/6,且 js 代码除外),值为空 "" 时则完全不替换
scrollD: 翻页动作触发点([滚动条] 与 [网页底部] 之间的距离),数值越大,越早开始翻页,一般是访问网页速度越慢,该值就需要越大,省略后默认 2000

scriptT: 单独插入 <script> 标签
Expand Down Expand Up @@ -1848,11 +1848,11 @@ function: {
if (curSite.pager.type === undefined) curSite.pager.type = 1; // 默认翻页模式 1
if (curSite.pager.scrollD === undefined) curSite.pager.scrollD = 2000; // 默认翻页触发线 2000
if (curSite.pager.interval === undefined) curSite.pager.interval = 500; // 默认间隔时间 500ms
if (curSite.pager.replaceE === undefined) { // 如果 replaceE 不存在,则默认替换 nextL
/*if (curSite.pager.replaceE === undefined) { // 如果 replaceE 不存在,则默认替换 nextL
if ((curSite.pager.type === 1 || curSite.pager.type === 3 || curSite.pager.type === 6) && curSite.pager.nextL && typeof curSite.pager.nextL !== 'function' && curSite.pager.nextL.search(/^js;/i) !== 0) {
curSite.pager.replaceE = curSite.pager.nextL
}
}
}*/
//console.log(curSite)
curSite.pageUrl = ''; // 下一页URL
windowScroll(function (direction, e) {
Expand Down Expand Up @@ -2182,7 +2182,7 @@ function: {
}

// 替换待替换元素
if (curSite.pager.replaceE) replaceElems(response);
if (curSite.pager.replaceE !== "") replaceElems(response);

// 插入 <script> 标签
if (curSite.pager.scriptT || curSite.pager.scriptT == 0) {
Expand Down Expand Up @@ -2224,7 +2224,7 @@ function: {
} else {
console.error('[自动无缝翻页] 获取主体元素失败...')
// 尝试替换元素看能不能继续翻页下去
/*if (curSite.pager.replaceE) {
/*if (curSite.pager.replaceE !== "") {
if (replaceElems(response)) { // 如果替换成功
console.log('[自动无缝翻页] 获取主体元素失败,尝试替换元素成功!')
// 当前页码 + 1
Expand Down Expand Up @@ -2423,8 +2423,27 @@ function: {
}
// 替换元素
function replaceElems(pageE, o = curSite.pager.replaceE, r = curSite.pager.replaceE) {
let oE = getAll(o),
rE = getAll(r, pageE, pageE);
let oE,rE;

if (curSite.pager.replaceE === undefined && curSite.pager.nextL && curSite.pager.nextL.search(/^js;/i) !== 0) { // 如果 replaceE 不存在,且 nextL 存在,且不是 js 代码
let a = getOne(curSite.pager.nextL) // 获取 nextL 元素,并判断该元素后面或前面是否有同类型的相邻兄弟元素
if ((a.nextElementSibling && a.nextElementSibling.tagName === a.tagName) || (a.previousElementSibling && a.previousElementSibling.tagName === a.tagName)) {
// nextL 元素后面或前面有同类型的相邻兄弟元素,则可以替换 nextL 的父元素
// 当 nextL 选择器为 xpath 时,直接末尾追加 /.. 即可选择其父元素
if (curSite.pager.nextL.slice(0,1) === '/' || curSite.pager.nextL.slice(0,2) === './' || curSite.pager.nextL.slice(0,2) === '(/' || curSite.pager.nextL.slice(0,3) === 'id(') {
o = r = curSite.pager.nextL + '/..'
oE = getAll(o)
rE = getAll(r, pageE, pageE)
} else { // 当 nextL 选择器为 css 时,则需要寻找所有 nextL 元素的父元素
oE = getAllParentElement(curSite.pager.nextL)
rE = getAllParentElement(curSite.pager.nextL, pageE, pageE)
}
} else { // 如果 nextL 元素后面或前面没有同类型的相邻兄弟元素,那么就只替换 nextL 元素
o = r = curSite.pager.nextL
oE = getAll(o)
rE = getAll(r, pageE, pageE)
}
}
if (oE.length != 0 && rE.length != 0 && oE.length === rE.length) {
for (let i = 0; i < oE.length; i++) {
oE[i].outerHTML = rE[i].outerHTML;
Expand Down Expand Up @@ -2523,6 +2542,18 @@ function: {
return getAllCSS(selector, contextNode);
}
}
// 获取所有父元素
function getAllParentElement(selector, contextNode = undefined, doc = document) {
contextNode = contextNode || doc;
const parents = [];
getAll(selector, contextNode, doc).forEach((next) => {
const parent = next.parentElement;
if (!parents.includes(parent)) {
parents.push(parent);
}
});
return parents
}
function createDocumentByString(e) {
if (e) {
if ('HTML' !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, 'application/xhtml+xml');
Expand Down Expand Up @@ -2552,14 +2583,9 @@ function: {
document.head.appendChild(document.createElement('base')).target = '_blank';

} else if (curSite.blank === 4) {
if (pageE) {
pageE.forEach(function (dd) {getAllCSS('a[href]:not([target="_blank"]):not([onclick]):not([href^="#"]):not([href^="javascript:"])',dd).forEach(function (a) {a.target = '_blank';});});
return pageE
}

let dd = toE5pop(getAll(curSite.pager.pageE));
if (dd && dd.parentElement != null) dd = dd.parentElement
getAllCSS('a[href]:not([target="_blank"]):not([onclick]):not([href^="#"]):not([href^="javascript:"])',dd).forEach(function (a) {a.target = '_blank';})
if (!pageE) pageE = getAll(curSite.pager.pageE)
pageE.forEach(function (dd) {getAllCSS('a[href]:not([target="_blank"]):not([onclick]):not([href^="#"]):not([href^="javascript:"])',dd).forEach(function (a) {a.target = '_blank';});});
return pageE

} else {
let d;
Expand Down Expand Up @@ -2697,9 +2723,10 @@ function: {
<li>脚本会自动格式化规则,因此<strong>无需手动缩进、换行</strong>,只需把规则<strong>插入默认的 { } 中间</strong>即可。</li>
</ul>
<pre style="white-space: pre-wrap !important;user-select: auto !important;">
// 下面示例是把所有规则都塞进去了,但实际上大部分都用不上,大多数网站只需要像第一个 "aaa" 这样的规则(replaceE 规则可以省略,省略后即默认替换 nextL 元素
// 下面示例是把所有规则都塞进去了,但实际上大部分都用不上,大多数网站只需要像第一个 "aaa" 这样的规则(replaceE 规则可以省略,脚本会自动判断
// "aaa" 是规则名,唯一!如果和 外置规则名 重复,则会将完全覆盖同名的外置规则,支持中文等各种字符
// "url" 是用来控制哪些网站中页面适用该规则,省略后代表该规则应用于全站
// "replaceE" 省略后将会自动判断是替换 nextL 元素还是 nextL 的父元素(当 nextL 元素后面或前面有 <a> 的相邻兄弟元素时替换其父元素,反之替换其自身,仅限模式1/3/6,且 js 代码除外),值为空 "" 时则完全不替换
// "scrollD" 是用来控制翻页敏感度的(越大就越早触发翻页,访问速度慢的网站需要调大,可省略(注意逗号),默认 2000)

// "inherits" 是继承标识,当你只需要对某个外置规则中 增删改 部分规则内容时(比如只是修改域名),那么就可以像下面第二个 "aaa" 规则一样写一个同名规则,规则内只有要修改的 host,以及 inherits 标识,这样脚本就会将外置规则中的 host 替换为自定义规则中的 host,其他规则则不变。即更灵活了,无需每次为了修改部分规则而去复制全部规则了,也不用担心我后续更新这个外置规则后,你还需要再次复制一遍来修改。。。
Expand Down
18 changes: 18 additions & 0 deletions other/Autopage/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,24 @@
"replaceE": ".search_stat"
}
},
"DirtyWarez": {
"host": "forum.dirtywarez.com",
"url": "/^\\/forums\\//",
"blank": 3,
"pager": {
"nextL": "//a[@class='text'][contains(text(),'>')]",
"pageE": "li.discussionListItem"
}
},
"Torrenting": {
"host": "torrenting.com",
"url": "/^\\/t($|\\?)/",
"blank": 4,
"pager": {
"nextL": ".page_nav>b+a",
"pageE": ".torrentsTableTr"
}
},
"CGpeers": {
"host": "cgpeers.to",
"url": "return (fun.lp() == '/torrents.php')",
Expand Down