Skip to content

Commit 2fd8495

Browse files
committed
Update DownloadAllContent.user.js
1 parent d7bdffe commit 2fd8495

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

DownloadAllContent/DownloadAllContent.user.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// @name:zh-TW 怠惰小説下載器
55
// @name:ja 怠惰者小説ダウンロードツール
66
// @namespace hoothin
7-
// @version 2.8.3.17
7+
// @version 2.8.3.18
88
// @description Lightweight web scraping script. Fetch and download main textual content from the current page, provide special support for novels
99
// @description:zh-CN 通用网站内容爬虫抓取工具,可批量抓取任意站点的小说、论坛内容等并保存为TXT文档
1010
// @description:zh-TW 通用網站內容爬蟲抓取工具,可批量抓取任意站點的小說、論壇內容等並保存為TXT文檔
@@ -977,6 +977,7 @@ if (window.top != window.self) {
977977
charsetValid = false;
978978
}
979979
} else charsetValid = false;
980+
var iframePool = [];
980981
function indexDownload(aEles, noSort){
981982
if(aEles.length<1)return;
982983
initTxtDownDiv();
@@ -1034,6 +1035,16 @@ if (window.top != window.self) {
10341035
item.innerText = prefix.replace(/\$i/g, ++curIndex) + item.innerText;
10351036
}
10361037
}
1038+
function getIframe() {
1039+
if (iframePool && iframePool.length) return iframePool.shift();
1040+
let iframe = document.createElement('iframe');
1041+
iframe.name = 'pagetual-iframe';
1042+
iframe.width = '100%';
1043+
iframe.height = '1000';
1044+
iframe.frameBorder = '0';
1045+
iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;flex:0;opacity:0!important;pointer-events:none!important;position:fixed;top:0px;left:0px;z-index:-2147483647;';
1046+
return iframe;
1047+
}
10371048
var insertSigns=[];
10381049
// var j=0,rCats=[];
10391050
var downIndex=0,downNum=0,downOnce=function(wait){
@@ -1188,7 +1199,7 @@ if (window.top != window.self) {
11881199
});
11891200
};
11901201
if (useIframe) {
1191-
let iframe = document.createElement('iframe'), inited = false, failedTimes = 0;
1202+
let iframe = getIframe(), inited = false, failedTimes = 0;
11921203
let loadtimeout;
11931204
let loadIframe = src => {
11941205
iframe.src = src;
@@ -1197,12 +1208,7 @@ if (window.top != window.self) {
11971208
iframe.src = src;
11981209
}, 20000);
11991210
};
1200-
iframe.name = 'pagetual-iframe';
1201-
iframe.width = '100%';
1202-
iframe.height = '1000';
1203-
iframe.frameBorder = '0';
12041211
iframe.sandbox = iframeSandbox || "allow-same-origin allow-scripts allow-popups allow-forms";
1205-
iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;flex:0;opacity:0!important;pointer-events:none!important;position:fixed;top:0px;left:0px;z-index:-2147483647;';
12061212
iframe.addEventListener('load', e => {
12071213
if (e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load') return;
12081214
if (inited) return;
@@ -1280,7 +1286,15 @@ if (window.top != window.self) {
12801286
} catch(e) {
12811287
console.debug("Stop as cors");
12821288
}
1283-
if (iframe && iframe.parentNode) iframe.parentNode.removeChild(iframe);
1289+
if (iframe && iframe.parentNode) {
1290+
try {
1291+
iframe.src = 'about:blank';
1292+
} catch (e) {
1293+
console.error("Error clearing iframe src:", e);
1294+
}
1295+
iframe.parentNode.removeChild(iframe);
1296+
iframePool.push(iframe);
1297+
}
12841298
}
12851299
setTimeout(() => {
12861300
checkIframe();

0 commit comments

Comments
 (0)