Skip to content

Commit

Permalink
修复 自定义翻页规则界面的规则示例中的 \\ 转义符错误显示为 \ 的问题(浏览器给转义符转义了...);
Browse files Browse the repository at this point in the history
优化 Firefox 浏览器中的兼容性问题(如 自定义翻页规则 输入框 无法多行显示,NGA 论坛未登录状态下无法翻页等)
  • Loading branch information
XIU2 committed Jul 21, 2024
1 parent 53a0573 commit 450ee51
Showing 1 changed file with 60 additions and 59 deletions.
119 changes: 60 additions & 59 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.6.16
// @version 6.6.17
// @author X.I.U
// @description ⭐无缝加载 下一页内容 至网页底部(类似瀑布流,无限滚动,无需手动点击下一页)⭐,目前支持:【所有「Discuz!、Flarum、phpBB、MyBB、Xiuno、XenForo、NexusPHP...」论坛】【百度、谷歌(Google)、必应(Bing)、搜狗、微信、360、Yahoo、Yandex 等搜索引擎...】、贴吧、豆瓣、知乎、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 @@ -1836,65 +1836,66 @@ function: {

// 翻页类型 1/3
function getPageE(url) {
// 依靠原生 XMLHttpRequest 尝试解决因缺失跨域 cookie 导致的问题(比如一些使用 Cloudflare CDN 人机验证的网站,会出现脚本后台获取到人机验证页面)
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.overrideMimeType('text/html; charset=' + (document.characterSet||document.charset||document.inputEncoding));

if (curSite.xRequestedWith === true) {xhr.setRequestHeader('x-requested-with', 'XMLHttpRequest')}
//(curSite.noReferer === true) ? xhr.setRequestHeader('Referer', ''):xhr.setRequestHeader('Referer', location.href)
//xhr.setRequestHeader('User-Agent', navigator.userAgent)
xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml')

xhr.timeout = 10000;
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) {
//console.log('URL:' + url, '最终 URL:' + xhr.responseURL, '返回内容:' + xhr.responseText)
processElems(createDocumentByString(xhr.responseText));
} else {
console.error('[自动无缝翻页] - 处理获取到的下一页内容时出现问题,请检查!', xhr.statusText);
}
};
xhr.onerror = function() {
console.log('URL:' + url, xhr.statusText)
GM_notification({text: '❌ 获取下一页失败...', timeout: 5000});
};
xhr.ontimeout = function() {
setTimeout(function(){curSite.pageUrl = '';}, 3000)
console.log('URL:' + url, xhr.statusText)
GM_notification({text: '❌ 获取下一页超时,可 3 秒后再次滚动网页重试(或尝试刷新网页)...', timeout: 5000});
};
xhr.send();

/*GM_xmlhttpRequest({
url: url,
method: 'GET',
overrideMimeType: 'text/html; charset=' + (document.characterSet||document.charset||document.inputEncoding),
headers: {
'x-requested-with': (curSite.xRequestedWith === true) ? 'XMLHttpRequest':null,
'Referer': (curSite.noReferer === true) ? null:location.href,
'User-Agent': navigator.userAgent,
'Accept': 'text/html,application/xhtml+xml,application/xml'
},
timeout: 10000,
onload: function (response) {
try {
//console.log('URL:' + url, '最终 URL:' + response.finalUrl, '返回内容:' + response.responseText)
processElems(createDocumentByString(response.responseText));
} catch (e) {
console.error('[自动无缝翻页] - 处理获取到的下一页内容时出现问题,请检查!', e, response.responseText);
if (!curSite.gmxhr) {
// 依靠原生 XMLHttpRequest 尝试解决因缺失跨域 cookie 导致的问题(比如一些使用 Cloudflare CDN 人机验证的网站,会出现脚本后台获取到人机验证页面)
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.overrideMimeType('text/html; charset=' + (document.characterSet||document.charset||document.inputEncoding));

if (curSite.xRequestedWith === true) {xhr.setRequestHeader('x-requested-with', 'XMLHttpRequest')}
//(curSite.noReferer === true) ? xhr.setRequestHeader('Referer', ''):xhr.setRequestHeader('Referer', location.href)
xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml')

xhr.timeout = 5000;
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) {
//console.log('URL:' + url, '最终 URL:' + xhr.responseURL, '返回内容:' + xhr.responseText)
processElems(createDocumentByString(xhr.responseText));
} else {
console.error('[自动无缝翻页] - 处理获取到的下一页内容时出现问题,请检查!', 'URL:' + url, '最终 URL:' + xhr.responseURL, '返回状态:' + xhr.statusText, '返回内容:' + xhr.responseText);
}
},
onerror: function (response) {
console.log('URL:' + url, response)
};
xhr.onerror = function() {
console.log('URL:' + url, xhr.statusText)
GM_notification({text: '❌ 获取下一页失败...', timeout: 5000});
},
ontimeout: function (response) {
};
xhr.ontimeout = function() {
setTimeout(function(){curSite.pageUrl = '';}, 3000)
console.log('URL:' + url, response)
console.log('URL:' + url, xhr.statusText)
GM_notification({text: '❌ 获取下一页超时,可 3 秒后再次滚动网页重试(或尝试刷新网页)...', timeout: 5000});
}
});*/
};
xhr.send();
} else {
GM_xmlhttpRequest({
url: url,
method: 'GET',
overrideMimeType: 'text/html; charset=' + (document.characterSet||document.charset||document.inputEncoding),
headers: {
'x-requested-with': (curSite.xRequestedWith === true) ? 'XMLHttpRequest':null,
'Referer': (curSite.noReferer === true) ? null:location.href,
'User-Agent': navigator.userAgent,
'Accept': 'text/html,application/xhtml+xml,application/xml'
},
timeout: 5000,
onload: function (response) {
try {
//console.log('URL:' + url, '最终 URL:' + response.finalUrl, '返回内容:' + response.responseText)
processElems(createDocumentByString(response.responseText));
} catch (e) {
console.error('[自动无缝翻页] - 处理获取到的下一页内容时出现问题,请检查!', e, 'URL:' + url, '最终 URL:' + response.finalUrl, '返回状态:' + response.statusText, '返回内容:' + response.responseText);
}
},
onerror: function (response) {
console.log('URL:' + url, response)
GM_notification({text: '❌ 获取下一页失败...', timeout: 5000});
},
ontimeout: function (response) {
setTimeout(function(){curSite.pageUrl = '';}, 3000)
console.log('URL:' + url, response)
GM_notification({text: '❌ 获取下一页超时,可 3 秒后再次滚动网页重试(或尝试刷新网页)...', timeout: 5000});
}
});
}
}
// 翻页类型 4
function getPageE_(url, type = '', method = 'GET', data = '', type2) {
Expand Down Expand Up @@ -2758,7 +2759,7 @@ function: {
},
"bbb": {
"host": ["bbb1.com", "bbb2.com"],
"url": "/^\\/s$/",
"url": "/^\\\\/s$/",
"style": ".aaaa {xxx: xxx}(如果只是为了单纯屏蔽隐藏某些元素,那么这里只需要写 CSS 选择器即可,脚本会自动在末尾加上 {display: none !important;} 的)",
"blank": 3,
"hiddenPN": true,
Expand All @@ -2783,7 +2784,7 @@ function: {
}
},
"这里也可以用中文": {
"host": "/\\.ccc\\.com/",
"host": "/\\\\.ccc\\\\.com/",
"url": "fun.isUrlC(); return (fun.lp() == '/' || fun.indexOF('/s') || fun.isMobile())",
"pager": {
"type": 2,
Expand All @@ -2800,7 +2801,7 @@ function: {
<details><summary style="cursor: pointer;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"><kbd><strong>「 点击展开 查看所有规则 」(可按 Ctrl+F 搜索规则,脚本内置的通用规则因格式限制无法列出)</strong></kbd></summary>
<pre id="Autopage_customRules_all" class="notranslate" style="overflow-y: scroll; overflow-x: hidden; height: 500px; word-break: break-all; white-space: pre-wrap;user-select: auto;"> </pre></details>
<textarea id="Autopage_customRules_textarea" style="min-width:95%; min-height:70%; display: block; margin: 10px 0 10px 0; white-space:nowrap; overflow:scroll; resize: auto; text-transform: initial;" placeholder="留空等于默认的 {},请把规则插入 {} 之间">${customRules}</textarea>
<textarea id="Autopage_customRules_textarea" style="min-width:95%; min-height:70%; display: block; margin: 10px 0 10px 0; white-space:pre; overflow:scroll; resize: revert; text-transform: initial;" placeholder="留空等于默认的 {},请把规则插入 {} 之间">${customRules}</textarea>
<button id="Autopage_customRules_save" style="margin-right: 20px;">保存并刷新</button><button id="Autopage_customRules_cancel">取消修改</button>
</div>`
document.documentElement.insertAdjacentHTML('beforeend', `<div id="Autopage_customRules" style="display: initial !important;position: fixed !important;z-index: 9999 !important;"></div>`);
Expand Down

0 comments on commit 450ee51

Please sign in to comment.