|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 自动无缝翻页 |
3 | | -// @version 3.6.0 |
| 3 | +// @version 3.6.1 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 无缝拼接下一页内容(瀑布流),目前支持:[所有「Discuz!、Flarum、phpBB、Xiuno、XenForo、DUX/XIU/D8/Begin(WP主题)」网站]、百度、谷歌、必应、搜狗、头条搜索、360 搜索、微信搜索、贴吧、豆瓣、微博、NGA、V2EX、B 站(Bilibili)、Pixiv、蓝奏云、煎蛋网、糗事百科、龙的天空、起点小说、IT之家、千图网、Pixabay、3DM、游侠网、游民星空、NexusMods、Steam 创意工坊、CS.RIN.RU、片库、茶杯狐、NO视频、低端影视、奈菲影视、音范丝、BT之家、萌番组、动漫花园、樱花动漫、爱恋动漫、AGE 动漫、Nyaa、SrkBT、RARBG、SubHD、423Down、不死鸟、扩展迷、极简插件、小众软件、动漫狂、漫画猫、漫画 DB、动漫之家、拷贝漫画、包子漫画、古风漫画网、Mangabz、PubMed、GreasyFork、Github、StackOverflow(以上仅一小部分,更多的写不下了... |
6 | 6 | // @match *://*/* |
|
1327 | 1327 | functionStart: function() {locationChange = true; |
1328 | 1328 | if (location.pathname == '/') { |
1329 | 1329 | forceTarget(); |
1330 | | - } else if (indexOF('/tags/') && self == top) { |
| 1330 | + } else if (indexOF('/tags/')/* && self == top*/) { |
1331 | 1331 | curSite = DBSite.pixiv; |
1332 | | - if (indexOF('/novels')) {insStyle('ul[class*="-1 "] > li {display: inline !important;}')} else {insStyle('a[href^="/premium/lead/lp"], div[class*="-0 "] > div[class*="-4 "] > section:first-of-type {display: none}');} |
| 1332 | + if (!indexOF('/novels'))insStyle('a[href^="/premium/lead/lp"], div[class*="-0 "] > div[class*="-4 "] > section:first-of-type {display: none}'); |
1333 | 1333 | } else if (indexOF('/users/') && /\/(artworks|illustrations|manga)/.test(location.pathname)) { |
1334 | 1334 | curSite = DBSite.pixiv_user; |
1335 | 1335 | } else if (indexOF('/artworks/')) { |
1336 | 1336 | setTimeout(function(){getXpath('//button[contains(string(), "查看全部") or contains(string(), "See all") or contains(string(), "すべて見る") or contains(string(), "모두 보기")]').click();}, 1000) |
1337 | 1337 | } |
1338 | 1338 | }, |
1339 | 1339 | forceTarget: true, |
| 1340 | + hiddenPN: true, |
1340 | 1341 | iframe: true, |
| 1342 | + insStyle: 'ul[class*="-1 "] > li {display: inline !important;} #root{margin-bottom: -175px;}', |
1341 | 1343 | pager: { |
1342 | | - type: 6, |
| 1344 | + type: 5, |
1343 | 1345 | nextL: 'css;a[aria-disabled="false"][class*="filterProps-Styled-Component"][href]:last-child', |
1344 | 1346 | pageE: '//ul[contains(@class, "-1 ")]/li', |
1345 | 1347 | insertP: ['//ul[contains(@class, "-1 ")]', 3], |
1346 | 1348 | replaceE: '//nav[./a[@aria-disabled="false"][contains(@class, "filterProps-Styled-Component")]]', |
1347 | 1349 | history: function() {if (/p=\d+/.test(location.search)) {return false;} else {return true;}}, |
1348 | | - loadTime: 1000, |
1349 | | - scrollD: 1000 |
| 1350 | + scrollD: 2000 |
1350 | 1351 | } |
1351 | 1352 | }, // Pixiv - 分类页 |
1352 | 1353 | pixiv_user: { |
1353 | 1354 | forceTarget: true, |
1354 | 1355 | hiddenPN: true, |
| 1356 | + insStyle: 'ul[class*="-1 "] > li {display: inline !important;} #root{margin-bottom: -125px;}', |
1355 | 1357 | pager: { |
1356 | 1358 | type: 5, |
1357 | 1359 | nextL: 'css;a[aria-disabled="false"][class*="filterProps-Styled-Component"][href]:last-child', |
|
1362 | 1364 | scrollD: 2000 |
1363 | 1365 | } |
1364 | 1366 | }, // Pixiv - 用户作品页 |
| 1367 | + vilipix: { |
| 1368 | + host: 'www.vilipix.com', |
| 1369 | + functionStart: function() {locationChange = true; |
| 1370 | + if (location.pathname == '/') { |
| 1371 | + forceTarget(); |
| 1372 | + } else if (indexOF('/tags/') || indexOF('/user/') || indexOF('/new') || indexOF('/ranking')) { |
| 1373 | + curSite = DBSite.vilipix; |
| 1374 | + } |
| 1375 | + }, |
| 1376 | + forceTarget: true, |
| 1377 | + pager: { |
| 1378 | + type: 6, |
| 1379 | + nextL: function() {let next = getCSS('li.number.active+li.number'); if (next) {return (location.origin + location.pathname + '?p=' + next.textContent)} else {return '';}}, |
| 1380 | + pageE: 'css;ul.illust-content > li', |
| 1381 | + insertP: ['css;ul.illust-content', 3], |
| 1382 | + replaceE: 'css;ul.el-pager', |
| 1383 | + history: function() {if (/p=\d+/.test(location.search)) {return false;} else {return true;}}, |
| 1384 | + loadTime: 800, |
| 1385 | + scrollD: 2000 |
| 1386 | + } |
| 1387 | + }, // vilipix |
1365 | 1388 | _58pic: { |
1366 | 1389 | host: 'www.58pic.com', |
1367 | 1390 | functionStart: function() {insStyle('.qt-model-t.login-model {display: none !important;}'); |
|
4875 | 4898 | } |
4876 | 4899 | if (curSite.insStyle) insStyle(curSite.insStyle) |
4877 | 4900 |
|
| 4901 | + // 对翻页模式 5 的子 iframe 添加一个跟随滚动的事件 |
| 4902 | + if (curSite.pager.type === 5 && self != top) { |
| 4903 | + var beforeScrollTop = document.documentElement.scrollTop || document.body.scrollTop |
| 4904 | + window.addEventListener('scroll', function (e) { |
| 4905 | + let scrollTop = window.parent.document.documentElement.scrollTop || window.parent.document.body.scrollTop, |
| 4906 | + clientHeight = window.parent.document.documentElement.clientHeight || window.parent.document.body.clientHeight, |
| 4907 | + scrollHeight = window.parent.document.documentElement.scrollHeight || window.parent.document.body.scrollHeight, |
| 4908 | + afterScrollTop = document.documentElement.scrollTop || document.body.scrollTop, |
| 4909 | + delta = afterScrollTop - beforeScrollTop; |
| 4910 | + if (delta == 0) return false; |
| 4911 | + beforeScrollTop = afterScrollTop; |
| 4912 | + //console.log(delta, scrollHeight - (scrollTop + clientHeight), '2222') |
| 4913 | + if (delta > 0 && scrollTop + clientHeight < scrollHeight) { |
| 4914 | + window.parent.scrollBy(0, delta*2); |
| 4915 | + } |
| 4916 | + }, false); |
| 4917 | + } |
| 4918 | + |
4878 | 4919 | curSite.pageUrl = ''; // 下一页URL |
4879 | 4920 | //console.log(curSite); |
4880 | 4921 | pageLoading(); // 自动无缝翻页 |
|
5778 | 5819 | // <<<<< 翻页类型 5(插入 iframe 方式来加载下一页)>>>>> |
5779 | 5820 | } else if (curSite.pager.type === 5) { |
5780 | 5821 | if (typeof curSite.pager.nextL == 'function') { |
5781 | | - curSite.pager.nextL(); |
| 5822 | + let tempUrl = curSite.pager.nextL(); |
| 5823 | + if (tempUrl === '' || curSite.pageUrl === tempUrl) return; |
| 5824 | + curSite.pageUrl = tempUrl; |
| 5825 | + insIframe(curSite.pageUrl); |
5782 | 5826 | } else if (getE_nextL(curSite.pager.nextL)) { |
5783 | 5827 | insIframe(curSite.pageUrl); |
5784 | 5828 | } |
5785 | 5829 |
|
5786 | 5830 | // <<<<< 翻页类型 6(通过 iframe 获取下一页动态加载内容)>>>>> |
5787 | 5831 | } else if (curSite.pager.type === 6) { |
5788 | 5832 | if (typeof curSite.pager.nextL == 'function') { |
5789 | | - curSite.pager.nextL(); |
| 5833 | + let tempUrl = curSite.pager.nextL(); |
| 5834 | + if (tempUrl === '' || curSite.pageUrl === tempUrl) return; |
| 5835 | + curSite.pageUrl = tempUrl; |
| 5836 | + insIframe_(curSite.pageUrl); |
5790 | 5837 | } else if (getE_nextL(curSite.pager.nextL)) { |
5791 | 5838 | insIframe_(curSite.pageUrl); |
5792 | 5839 | } |
|
5807 | 5854 | // 翻页类型 5(插入 iframe 方式加载下一页) |
5808 | 5855 | function insIframe(src) { |
5809 | 5856 | // 停用当前页面翻页 |
| 5857 | + if (!pausePage) return |
5810 | 5858 | curSite.SiteTypeID = 0; |
| 5859 | + pausePage = false |
| 5860 | + |
| 5861 | + var beforeScrollTop = document.documentElement.scrollTop || document.body.scrollTop |
5811 | 5862 | // 当滚动条到底部时(即完全显示 iframe 框架),隐藏当前页面的滚动条 |
5812 | | - window.addEventListener('scroll', function (e) { |
| 5863 | + window.addEventListener('scroll', function () { |
5813 | 5864 | let scrollTop = document.documentElement.scrollTop || document.body.scrollTop, |
| 5865 | + clientHeight = document.documentElement.clientHeight || document.body.clientHeight, |
5814 | 5866 | scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight, |
5815 | | - clientHeight = document.documentElement.clientHeight || document.body.clientHeight |
5816 | | - if (scrollTop + clientHeight + 10 >= scrollHeight) { |
5817 | | - if (!getCSS('#xiu-scroll')) { |
5818 | | - let newStyle = document.createElement('style'); newStyle.id = 'xiu-scroll'; |
5819 | | - newStyle.textContent = 'html::-webkit-scrollbar {width: 0 !important;height: 0 !important;} html {scrollbar-width: none !important;}'; |
5820 | | - if (curSite.pager.insStyle) newStyle.textContent += curSite.pager.insStyle; |
5821 | | - document.lastElementChild.appendChild(newStyle); |
5822 | | - } |
5823 | | - } else { |
5824 | | - if (getCSS('#xiu-scroll')) { |
5825 | | - getCSS('#xiu-scroll').remove(); |
5826 | | - } |
| 5867 | + afterScrollTop = document.documentElement.scrollTop || document.body.scrollTop, |
| 5868 | + delta = afterScrollTop - beforeScrollTop; |
| 5869 | + if (delta == 0) return false; |
| 5870 | + beforeScrollTop = afterScrollTop; |
| 5871 | + |
| 5872 | + //console.log(delta, scrollHeight - (scrollTop + clientHeight + 10), '1111') |
| 5873 | + if (delta > 0 && scrollTop + clientHeight + 10 >= scrollHeight && !getCSS('#xiu-scroll')) { |
| 5874 | + let newStyle = document.createElement('style'); newStyle.id = 'xiu-scroll'; |
| 5875 | + newStyle.textContent = 'html::-webkit-scrollbar {width: 0 !important;height: 0 !important;} html {scrollbar-width: none !important;}'; |
| 5876 | + if (curSite.pager.insStyle) newStyle.textContent += curSite.pager.insStyle; |
| 5877 | + document.lastElementChild.appendChild(newStyle); |
| 5878 | + } else if (delta < 0 && getCSS('#xiu-scroll')) { |
| 5879 | + getCSS('#xiu-scroll').remove(); |
5827 | 5880 | } |
5828 | | - //console.log(`${scrollTop} + ${clientHeight} >= ${scrollTop + clientHeight} / ${scrollHeight}`) |
5829 | 5881 | }, false); |
5830 | 5882 |
|
5831 | 5883 | // 创建 iframe |
|
5854 | 5906 | pausePage = false |
5855 | 5907 |
|
5856 | 5908 | // 如果不存在,则创建一个 iframe |
5857 | | - let iframe = document.getElementById('xiu2_iframe'); |
| 5909 | + let iframe = document.getElementById('xiu_iframe'); |
5858 | 5910 | if (!iframe) { |
5859 | 5911 | iframe = document.createElement('iframe'); |
5860 | | - iframe.style = 'position: absolute; width: 100%; height: 100%; border: none; display: none;'; |
5861 | | - iframe.id = 'xiu2_iframe'; |
| 5912 | + iframe.style = 'position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; border: none; z-index: -999; /*visibility: hidden;*/'; |
| 5913 | + iframe.id = 'xiu_iframe'; |
5862 | 5914 | iframe.src = src; |
5863 | 5915 | } |
5864 | 5916 |
|
5865 | 5917 | // 加载完成后才继续 |
5866 | 5918 | iframe.onload = function() { |
5867 | | - iframe.contentWindow.scrollTo(0, 999999); // 滚动到底部,以触发网页的滚动条相关加载事件 |
| 5919 | + //iframe.contentWindow.scrollTo(0, 999999); // 滚动到底部,以触发网页的滚动条相关加载事件 |
5868 | 5920 | //iframe.contentWindow.scrollTo({top: 9999999, behavior: 'smooth'}); |
5869 | 5921 | if (!curSite.pager.loadTime) curSite.pager.loadTime = 100; // 默认 100ms |
5870 | | - setTimeout(function() { |
5871 | | - //console.log(getOne(curSite.pager.insertP[0], iframe.contentWindow.document)) |
5872 | | - processResult(iframe.contentWindow.document); // 插入/替换元素等 |
5873 | | - pausePage = true; // 恢复翻页 |
5874 | | - }, curSite.pager.loadTime) // 预留加载时间,确保网页加载完成 |
| 5922 | + //console.log(curSite.pager.loadTime, curSite.pager.loadTime/30) |
| 5923 | + console.time('sort'); |
| 5924 | + let time1 = 0 ,time2 = setInterval(function(){ |
| 5925 | + let scrollHeight = (iframe.contentWindow.document.documentElement.scrollHeight || iframe.contentWindow.document.body.scrollHeight)/10 |
| 5926 | + iframe.contentWindow.scrollTo(0, 999999); |
| 5927 | + iframe.contentWindow.scrollTo(0, scrollHeight*time1); |
| 5928 | + //console.log(time1, iframe.contentWindow.document.documentElement.scrollHeight || iframe.contentWindow.document.body.scrollHeight) |
| 5929 | + if (++time1 == 10) { |
| 5930 | + console.timeEnd('sort'); |
| 5931 | + clearInterval(time2); |
| 5932 | + processResult(iframe.contentWindow.document); // 插入/替换元素等 |
| 5933 | + //console.log(iframe.contentWindow.document.documentElement.scrollHeight || iframe.contentWindow.document.body.scrollHeight) |
| 5934 | + pausePage = true; // 恢复翻页 |
| 5935 | + } |
| 5936 | + }, curSite.pager.loadTime/10) |
5875 | 5937 | } |
5876 | 5938 |
|
5877 | 5939 | // 插入 iframe(如果已存在则直接改 src) |
5878 | | - if (document.getElementById('xiu2_iframe')) { |
| 5940 | + if (document.getElementById('xiu_iframe')) { |
5879 | 5941 | iframe.src = src; |
5880 | 5942 | } else { |
5881 | 5943 | document.lastElementChild.appendChild(iframe); |
|
5950 | 6012 | } |
5951 | 6013 |
|
5952 | 6014 |
|
5953 | | - // 翻页类型 1/3 // 修改自 https://greasyfork.org/scripts/14178 、 https://github.com/machsix/Super-preloader |
| 6015 | + // 翻页类型 1/3 (修改自 https://greasyfork.org/scripts/14178 、 https://github.com/machsix/Super-preloader) |
5954 | 6016 | var ShowPager = { |
5955 | 6017 | getFullHref: function (e) { |
5956 | 6018 | if (e != null && e.nodeType === 1 && e.href && e.href.slice(0,4) === 'http') return e.href; |
|
0 commit comments