Skip to content

Commit 3c0b61e

Browse files
committed
fix
1 parent 8820802 commit 3c0b61e

1 file changed

Lines changed: 26 additions & 34 deletions

File tree

DownloadAllContent/DownloadAllContent.user.js

Lines changed: 26 additions & 34 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.13
7+
// @version 1.15
88
// @description Fetch and download main content on current page, provide special support for chinese novel
99
// @description:zh-CN 通用网站内容抓取工具,可批量抓取小说、论坛内容等并保存为TXT文档
1010
// @description:zh-TW 通用網站內容抓取工具,可批量抓取小說、論壇內容等並保存為TXT文檔
@@ -108,30 +108,30 @@
108108
var i,j,k,rStr="",pageData=(doc.body?doc.body:doc).cloneNode(true),delList=[];
109109
[].forEach.call(pageData.querySelectorAll("script,style,link,img"),function(item){delList.push(item);});
110110
[].forEach.call(delList,function(item){item.parentNode.removeChild(item);});
111-
var largestContent,contents=pageData.querySelectorAll("span,div,article,p,td");
111+
[].forEach.call(pageData.querySelectorAll("font.jammer"),function(item){
112+
item.parentNode.removeChild(item);
113+
});
114+
[].forEach.call(pageData.querySelectorAll("span"),function(item){
115+
if(item.style && item.style.display=="none")
116+
item.parentNode.removeChild(item);
117+
});
118+
var largestContent,contents=pageData.querySelectorAll("span,div,article,p,td"),largestNum=0;
112119
for(i=0;i<contents.length;i++){
113-
let content=contents[i],hasText=false,allSingle=true,item;
120+
let content=contents[i],hasText=false,allSingle=true,item,curNum=0;
114121
for(j=content.childNodes.length-1;j>=0;j--){
115122
item=content.childNodes[j];
116-
if(item.nodeType==3 && /^\s*$/.test(item.data))
117-
item.parentNode.removeChild(item);
123+
if(item.nodeType==3){
124+
if(/^\s*$/.test(item.data))
125+
item.parentNode.removeChild(item);
126+
else hasText=true;
127+
128+
}
118129
}
119130
for(j=content.childNodes.length-1;j>=0;j--){
120131
item=content.childNodes[j];
121132
if(item.nodeType==1 && !/^(I|A|STRONG|B|FONT|BR)$/.test(item.tagName) && /^\s*$/.test(item.innerHTML))
122133
item.parentNode.removeChild(item);
123134
}
124-
[].forEach.call(content.querySelectorAll("font.jammer"),function(item){
125-
item.parentNode.removeChild(item);
126-
});
127-
[].forEach.call(content.querySelectorAll("span"),function(item){
128-
if(item.style && item.style.display=="none")
129-
item.parentNode.removeChild(item);
130-
});
131-
[].forEach.call(content.childNodes,function(item){
132-
if(item.nodeType==3 && item.data && !/^\s*$/.test(item.data))
133-
hasText=true;
134-
});
135135
if(content.childNodes.length>1){
136136
for(j=0;j<content.childNodes.length;j++){
137137
item=content.childNodes[j];
@@ -144,33 +144,25 @@
144144
}
145145
}
146146
if(!allSingle)break;
147-
delList=[];
148-
[].forEach.call(item.childNodes,function(n){if((n.nodeType==3 && /^\s*$/.test(n.data)) || (n.nodeType==1 && /^\s*$/.test(n.textContent)))delList.push(n);});
149-
[].forEach.call(delList,function(n){n.parentNode.removeChild(n);});
150147
}
151148
}
152149
}else{
153150
allSingle=false;
154151
}
155-
if(!allSingle){
152+
if(allSingle){
153+
curNum=(navigator.userAgent.toLowerCase().indexOf('firefox')==-1?content.innerText.length:content.textContent.length);
154+
}else {
156155
if(!hasText)continue;
157-
if(content.firstChild && (
158-
(content.firstChild.nodeType!=3 && !/^(I|A|STRONG|B|FONT|BR)$/.test(content.firstChild.tagName)) ||
159-
(content.firstChild.nodeType==3 && /^\s*$/.test(content.firstChild.data) &&
160-
(!content.childNodes[1] || !(content.childNodes[1].nodeType==3 || /^(I|A|STRONG|B|FONT|BR)$/.test(content.childNodes[1].tagName))))
161-
))
162-
continue;
163156
if(pageData==document && content.offsetWidth<=0 && content.offsetHeight<=0)
164157
continue;
158+
[].forEach.call(content.childNodes,function(item){
159+
if(item.nodeType==3)
160+
curNum+=item.data.length;
161+
});
165162
}
166-
if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){
167-
if(!largestContent || largestContent.textContent.length<content.textContent.length){
168-
largestContent=content;
169-
}
170-
}else{
171-
if(!largestContent || largestContent.innerText.length<content.innerText.length){
172-
largestContent=content;
173-
}
163+
if(curNum>largestNum){
164+
largestNum=curNum;
165+
largestContent=content;
174166
}
175167
}
176168
if(!largestContent)return i18n.error;

0 commit comments

Comments
 (0)