MCPcopy Index your code
hub / github.com/XIU2/UserScript / insIframe

Function insIframe

Autopage.user.js:1809–1885  ·  view source on GitHub ↗
(src)

Source from the content-addressed store, hash-verified

1807 }
1808 // 翻页类型 5(插入 iframe 方式加载下一页,无限套娃)
1809 function insIframe(src) {
1810 // 停用当前页面翻页
1811 if (curSite.SiteTypeID == 0) return
1812 curSite.SiteTypeID = 0;
1813
1814 // 创建 iframe
1815 let iframe = document.createElement('iframe');
1816 iframe.id = 'Autopage_iframe';
1817 iframe.src = src.replace(/#.+$/,'');
1818
1819 document.documentElement.appendChild(document.createElement('style')).textContent = 'iframe#Autopage_iframe {position: absolute !important; width: 100% !important; height: 100% !important; border: none !important;}';
1820
1821 var beforeScrollTop = document.documentElement.scrollTop || document.body.scrollTop
1822 // 当滚动条到底部时(即完全显示 iframe 框架),隐藏当前页面的滚动条
1823 window.addEventListener('scroll', function () {
1824 let scrollTop = document.documentElement.scrollTop || document.body.scrollTop,
1825 clientHeight = document.documentElement.clientHeight || document.body.clientHeight,
1826 scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight,
1827 afterScrollTop = document.documentElement.scrollTop || document.body.scrollTop,
1828 delta = afterScrollTop - beforeScrollTop;
1829 if (delta == 0) return false;
1830 beforeScrollTop = afterScrollTop;
1831
1832 //console.log(delta, (scrollTop + clientHeight + 10), scrollHeight, '1111')
1833 if (delta > 0 && scrollTop + clientHeight + 10 >= scrollHeight && !getCSS('#Autopage_iframe-scroll')) {
1834 let newStyle = document.createElement('style'); newStyle.id = 'Autopage_iframe-scroll';
1835 newStyle.textContent = 'html::-webkit-scrollbar, body::-webkit-scrollbar {width: 0 !important;height: 0 !important;} html, body {scrollbar-width: none !important;}';
1836 if (curSite.pager.style) newStyle.textContent += curSite.pager.style;
1837 document.documentElement.appendChild(newStyle);
1838
1839 // 恢复 iframe 的滚动条
1840 if (iframe.contentWindow.document.querySelectorAll('#Autopage_iframe-scroll-hidden')) iframe.contentWindow.document.querySelectorAll('#Autopage_iframe-scroll-hidden').forEach((o)=>{o.remove();});
1841
1842 // 给予 iframe 焦点
1843 iframe.focus();
1844 if (iframe.contentWindow.document.body) {iframe.contentWindow.document.body.focus(); iframe.contentWindow.document.body.click();}
1845 } else if (delta < 0 && scrollTop + clientHeight + 10 <= scrollHeight && getCSS('#Autopage_iframe-scroll')) {
1846 getCSS('#Autopage_iframe-scroll').remove();
1847 // 再次禁用 iframe 的滚动条
1848 if (!iframe.contentWindow.document.getElementById('Autopage_iframe-scroll-hidden')) {
1849 let newStyle = document.createElement('style'); newStyle.id = 'Autopage_iframe-scroll-hidden';
1850 newStyle.textContent = 'html, body {overflow: hidden !important;}';
1851 iframe.contentWindow.document.documentElement.appendChild(newStyle);
1852 }
1853 }
1854 }, false);
1855
1856 // 加载完成后才继续
1857 iframe.onload = function() {
1858 // 暂时禁用 iframe 的滚动条
1859 if (!getCSS('#Autopage_iframe-scroll') && !iframe.contentWindow.document.getElementById('Autopage_iframe-scroll-hidden')) {
1860
1861 let newStyle = document.createElement('style'); newStyle.id = 'Autopage_iframe-scroll-hidden';
1862 newStyle.textContent = 'html, body {overflow: hidden !important;}';
1863 iframe.contentWindow.document.documentElement.appendChild(newStyle);
1864 }
1865
1866 // 添加历史记录

Callers

nothing calls this directly

Calls 3

getCSSFunction · 0.85
addHistoryFunction · 0.85
pageNumIncrementFunction · 0.85

Tested by

no test coverage detected