Skip to content

Commit 225f2ea

Browse files
committed
fix
1 parent 3a4dfd7 commit 225f2ea

1 file changed

Lines changed: 29 additions & 18 deletions

File tree

DownloadAllContent/DownloadAllContent.user.js

Lines changed: 29 additions & 18 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 1.03
7+
// @version 1.05
88
// @description Fetch and download main content on current page
99
// @description:zh-CN 通用网站内容抓取工具,可批量抓取小说、论坛内容等并保存为TXT文档
1010
// @description:zh-TW 通用網站內容抓取工具,可批量抓取小說、論壇內容等並保存為TXT文檔
@@ -108,27 +108,38 @@
108108
[].forEach.call(delList,function(item){item.parentNode.removeChild(item);});
109109
var largestContent,contents=pageData.querySelectorAll("span,div,article,p,td");
110110
for(i=0;i<contents.length;i++){
111-
let content=contents[i],hasText=false;
111+
let content=contents[i],hasText=false,allSingle=true,item;
112+
for(j=content.childNodes.length-1;j>=0;j--){
113+
item=content.childNodes[j];
114+
if(item.nodeType==3 && /^\s*$/.test(item.data))
115+
item.parentNode.removeChild(item);
116+
}
112117
[].forEach.call(content.childNodes,function(item){
113118
if(item.nodeType==3 && item.data && !/^\s*$/.test(item.data))
114119
hasText=true;
115120
});
116-
if(!hasText)continue;
117-
if(content.childNodes){
118-
for(j=content.childNodes.length-1;j>=0;j--){
119-
var item=content.childNodes[j];
120-
if(item.nodeType==3 && /^\s*$/.test(item.data))
121-
item.parentNode.removeChild(item);
121+
if(content.childNodes.length>1){
122+
for(j=0;j<content.childNodes.length;j++){
123+
item=content.childNodes[j];
124+
if(item.nodeType==1 && item.firstChild && item.firstChild.nodeType!=3){
125+
allSingle=false;
126+
break;
127+
}
122128
}
129+
}else{
130+
allSingle=false;
131+
}
132+
if(!allSingle){
133+
if(!hasText)continue;
134+
if(content.firstChild && (
135+
(content.firstChild.nodeType!=3 && !/^(I|A|STRONG|B|FONT|BR)$/.test(content.firstChild.tagName)) ||
136+
(content.firstChild.nodeType==3 && /^\s*$/.test(content.firstChild.data) &&
137+
(!content.childNodes[1] || !(content.childNodes[1].nodeType==3 || /^(I|A|STRONG|B|FONT|BR)$/.test(content.childNodes[1].tagName))))
138+
))
139+
continue;
140+
if(pageData==document && content.offsetWidth<=0 && content.offsetHeight<=0)
141+
continue;
123142
}
124-
if(content.firstChild && (
125-
(content.firstChild.nodeType!=3 && !/^(I|A|STRONG|B|FONT|BR)$/.test(content.firstChild.tagName)) ||
126-
(content.firstChild.nodeType==3 && /^\s*$/.test(content.firstChild.data) &&
127-
(!content.childNodes[1] || !(content.childNodes[1].nodeType==3 || /^(I|A|STRONG|B|FONT|BR)$/.test(content.childNodes[1].tagName))))
128-
))
129-
continue;
130-
if(pageData==document && content.offsetWidth<=0 && content.offsetHeight<=0)
131-
continue;
132143
if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){
133144
if(!largestContent || largestContent.textContent.length<content.textContent.length){
134145
largestContent=content;
@@ -146,7 +157,7 @@
146157
let childNode=childNodes[j];
147158
if(childNode.nodeType==3 && childNode.data && !/^\s*$/.test(childNode.data))hasText=true;
148159
if(childNode.tagName=="BR")cStr+="\r\n";
149-
else if(childNode.textContent)cStr+=childNode.textContent.replace(/\s*/," ");
160+
else if(childNode.textContent)cStr+=childNode.textContent.replace(/ +/g," ").replace(/([^\r]|^)\n([^\r]|$)/g,"$1\r\n$2");
150161
}
151162
if(hasText || noTextEnable)rStr+=cStr+"\r\n";
152163
}
@@ -176,7 +187,7 @@
176187
var aEles=document.querySelectorAll("a"),list=[];
177188
for(var i=0;i<aEles.length;i++){
178189
var aEle=aEles[i];
179-
if(aEle.href && /[\d||||||||||||||||]+[|||||||]||\s*|\s*|\s*|\s*|\s*|\s*|\s*|\s*|\s*|\s*|[\d||||||||||||||||]+/.test(aEle.innerHTML)){
190+
if(aEle.href && /.+[|||||||]||\s*|\s*|\s*|\s*|\s*|\s*|\s*|\s*|\s*|\s*|[\d|||||||||||||||||-]+(|)/.test(aEle.innerHTML)){
180191
list.push(aEle);
181192
}
182193
}

0 commit comments

Comments
 (0)