Skip to content

Commit ac77f71

Browse files
committed
fix
1 parent 485b6d4 commit ac77f71

1 file changed

Lines changed: 19 additions & 37 deletions

File tree

DownloadAllContent/DownloadAllContent.user.js

Lines changed: 19 additions & 37 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 0.6
7+
// @version 0.7
88
// @description Fetch and download main content on current page
99
// @description:zh-CN 通用网站内容抓取工具,可批量抓取小说、论坛内容等并保存为TXT文档
1010
// @description:zh-TW 通用網站內容抓取工具,可批量抓取小說、論壇內容等並保存為TXT文檔
@@ -85,31 +85,17 @@
8585
}
8686
for(let i=0;i<aEles.length;i++){
8787
let aTag=aEles[i];
88+
var contentType=document.querySelector("meta[http-equiv=Content-Type]");
8889
GM_xmlhttpRequest({
8990
method: 'GET',
9091
url: aTag.href,
92+
overrideMimeType:contentType?contentType.content:null,
9193
onload: function(result) {
9294
var doc = getDocEle(result.responseText);
9395
if (!doc) {
9496
return;
9597
}
96-
var contentType=doc.querySelector("meta[http-equiv=Content-Type]");
97-
if(contentType && !/utf\-?8/i.test(contentType.content)){
98-
GM_xmlhttpRequest({
99-
method: 'GET',
100-
url: aTag.href,
101-
overrideMimeType:contentType.content,
102-
onload: function(result) {
103-
var doc = getDocEle(result.responseText);
104-
if (!doc) {
105-
return;
106-
}
107-
processDoc(i, aTag, doc);
108-
}
109-
});
110-
}else{
111-
processDoc(i, aTag, doc);
112-
}
98+
processDoc(i, aTag, doc);
11399
}
114100
});
115101
}
@@ -139,27 +125,23 @@
139125
}
140126
}
141127
var childlist=pageData.querySelectorAll(largestContent.tagName);
128+
function getRightStr(ele, noTextEnable){
129+
let childNodes=ele.childNodes,cStr="\r\n",hasText=false;
130+
for(let j=0;j<childNodes.length;j++){
131+
let childNode=childNodes[j];
132+
if(childNode.nodeType==3 && childNode.data && !/^\s*$/.test(childNode.data))hasText=true;
133+
if(childNode.tagName=="BR")cStr+="\r\n";
134+
else if(!/SCRIPT|STYLE/.test(childNode.tagName) && childNode.textContent)cStr+=childNode.textContent.replace(/\s*/," ");
135+
}
136+
if(hasText || noTextEnable)rStr+=cStr;
137+
}
142138
for(i=0;i<childlist.length;i++){
143139
var child=childlist[i];
144-
if(largestContent.className && largestContent.className==child.className){
145-
let childNodes=child.childNodes,cStr="\r\n",hasText=false;
146-
for(let j=0;j<childNodes.length;j++){
147-
let childNode=childNodes[j];
148-
if(childNode.tagName=="BR")cStr+="\r\n";
149-
else if(!/SCRIPT|STYLE/.test(childNode.tagName) && childNode.textContent)cStr+=childNode.textContent.replace(/\s*/," ");
150-
}
151-
rStr+=cStr;
152-
}else {
153-
if(child.firstChild && ((child.firstChild.nodeType!=3 && !/^[I|A]$/.test(child.firstChild.tagName)) || (/^\s*$/.test(child.firstChild.data) && (!child.childNodes[1] || !/^[I|A]$/.test(child.childNodes[1].tagName)))))continue;
154-
if(getDepth(child)==getDepth(largestContent)){
155-
let childNodes=child.childNodes,cStr="\r\n",hasText=false;
156-
for(let j=0;j<childNodes.length;j++){
157-
let childNode=childNodes[j];
158-
if(childNode.nodeType==3 && childNode.data && !/^\s*$/.test(childNode.data))hasText=true;
159-
if(childNode.tagName=="BR")cStr+="\r\n";
160-
else if(!/SCRIPT|STYLE/.test(childNode.tagName) && childNode.textContent)cStr+=childNode.textContent.replace(/\s*/," ");
161-
}
162-
if(hasText)rStr+=cStr;
140+
if(getDepth(child)==getDepth(largestContent)){
141+
if(largestContent.className && largestContent.className==child.className){
142+
getRightStr(child, true);
143+
}else {
144+
getRightStr(child, false);
163145
}
164146
}
165147
}

0 commit comments

Comments
 (0)