(url)
| 1684 | |
| 1685 | // 翻页类型 1/3 |
| 1686 | function getPageE(url) { |
| 1687 | // Chrome 浏览器可以依靠改用原生 XMLHttpRequest 尝试解决因缺失跨域 cookie 导致的问题(比如一些使用 Cloudflare CDN 人机验证的网站,会出现脚本后台获取到人机验证页面) |
| 1688 | // Firefox 浏览器则需要使用 GM_xmlhttpRequest 的 cookiePartition 参数来解决(该参数要 Tampermonkey v5.2 及以上才有) |
| 1689 | // 如果翻页规则有 curSite.gmxhr 或是 Firefox 浏览器,则依然使用 GM_xmlhttpRequest+cookiePartition,反之则使用原生 XMLHttpRequest |
| 1690 | if (curSite.gmxhr || navigator.userAgent.includes('Firefox')) { |
| 1691 | GM_xmlhttpRequest({ |
| 1692 | url: url, |
| 1693 | method: 'GET', |
| 1694 | //overrideMimeType: 'text/html; charset=' + (document.characterSet||document.charset||document.inputEncoding), |
| 1695 | responseType: 'arraybuffer', // Firefox 浏览器下 Tampermonkey 访问 GBK 网站时会乱码,只能改为 TextDecoder 手动转换编码 |
| 1696 | headers: { |
| 1697 | 'x-requested-with': (curSite.xRequestedWith === true) ? 'XMLHttpRequest':null, |
| 1698 | 'Referer': (curSite.noReferer === true) ? null:location.href, |
| 1699 | 'Accept': 'text/html,application/xhtml+xml,application/xml' |
| 1700 | }, |
| 1701 | cookiePartition: { // https://github.com/Tampermonkey/tampermonkey/issues/2057 |
| 1702 | topLevelSite: location.origin |
| 1703 | }, |
| 1704 | timeout: 5000, |
| 1705 | onload: function (response) { |
| 1706 | try { |
| 1707 | //console.log('URL:' + url, '最终 URL:' + response.finalUrl, '返回内容:' + response.responseText, response) |
| 1708 | processElems(createDocumentByString((new TextDecoder((document.characterSet||document.charset||document.inputEncoding))).decode(response.response))); |
| 1709 | //processElems(createDocumentByString(response.responseText)); |
| 1710 | } catch (e) { |
| 1711 | console.error('[自动无缝翻页] - 处理获取到的下一页内容时出现问题,请检查!\n', e, '\nURL:' + url, '\n最终 URL:' + response.finalUrl, '\n返回状态:' + response.statusText, '\n返回内容:' + response.responseText); |
| 1712 | } |
| 1713 | }, |
| 1714 | onerror: function (response) { |
| 1715 | console.log('URL:' + url, response) |
| 1716 | GM_notification({text: '❌ 获取下一页失败...', timeout: 5000}); |
| 1717 | }, |
| 1718 | ontimeout: function (response) { |
| 1719 | setTimeout(function(){curSite.pageUrl = '';}, 3000) |
| 1720 | console.log('URL:' + url, response) |
| 1721 | GM_notification({text: '❌ 获取下一页超时,可 3 秒后再次滚动网页重试(或尝试刷新网页)...', timeout: 5000}); |
| 1722 | } |
| 1723 | }); |
| 1724 | } else { |
| 1725 | const xhr = new XMLHttpRequest(); |
| 1726 | xhr.open('GET', url, true); |
| 1727 | xhr.overrideMimeType('text/html; charset=' + (document.characterSet||document.charset||document.inputEncoding)); |
| 1728 | |
| 1729 | if (curSite.xRequestedWith === true) {xhr.setRequestHeader('x-requested-with', 'XMLHttpRequest')} |
| 1730 | //(curSite.noReferer === true) ? xhr.setRequestHeader('Referer', ''):xhr.setRequestHeader('Referer', location.href) |
| 1731 | xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml') |
| 1732 | |
| 1733 | xhr.timeout = 5000; |
| 1734 | xhr.onload = function() { |
| 1735 | try { |
| 1736 | //console.log('URL:' + url, '最终 URL:' + xhr.responseURL, '返回内容:' + xhr.responseText) |
| 1737 | processElems(createDocumentByString(xhr.responseText)); |
| 1738 | } catch (e) { |
| 1739 | console.error('[自动无缝翻页] - 处理获取到的下一页内容时出现问题,请检查!\n', e, '\nURL:' + url, '\n最终 URL:' + xhr.responseURL, '\n返回状态:' + xhr.statusText, '\n返回内容:' + xhr.responseText); |
| 1740 | } |
| 1741 | }; |
| 1742 | xhr.onerror = function() { |
| 1743 | console.log('URL:' + url, xhr.statusText) |
nothing calls this directly
no test coverage detected