|
4 | 4 | // @name:zh-TW 懶人小説下載器 |
5 | 5 | // @name:ja 怠惰者小説ダウンロードツール |
6 | 6 | // @namespace hoothin |
7 | | -// @version 0.5 |
| 7 | +// @version 0.6 |
8 | 8 | // @description Fetch and download main content on current page |
9 | 9 | // @description:zh-CN 通用网站内容抓取工具,可批量抓取小说、论坛内容等并保存为TXT文档 |
10 | 10 | // @description:zh-TW 通用網站內容抓取工具,可批量抓取小說、論壇內容等並保存為TXT文檔 |
|
123 | 123 | if(content.firstChild && ( |
124 | 124 | (content.firstChild.nodeType!=3 && !/^[I|A]$/.test(content.firstChild.tagName)) || |
125 | 125 | (/^\s*$/.test(content.firstChild.data) && |
126 | | - (!content.childNodes[1]||!/^[I|A]$/.test(content.childNodes[1].tagName))) |
| 126 | + (!content.childNodes[1] || !/^[I|A]$/.test(content.childNodes[1].tagName))) |
127 | 127 | )) |
128 | 128 | continue; |
129 | | - if(pageData==document && content.offsetWidth <= 0 && content.offsetHeight <= 0) |
| 129 | + if(pageData==document && content.offsetWidth<=0 && content.offsetHeight<=0) |
130 | 130 | continue; |
131 | 131 | if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){ |
132 | 132 | if(!largestContent || largestContent.textContent.length<content.textContent.length){ |
|
142 | 142 | for(i=0;i<childlist.length;i++){ |
143 | 143 | var child=childlist[i]; |
144 | 144 | if(largestContent.className && largestContent.className==child.className){ |
145 | | - }else 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; |
146 | | - if(getDepth(child)==getDepth(largestContent)){ |
147 | 145 | let childNodes=child.childNodes,cStr="\r\n",hasText=false; |
148 | | - for(var j=0;j<childNodes.length;j++){ |
149 | | - var childNode=childNodes[j]; |
150 | | - if(childNode.nodeType==3 && childNode.data && !/^\s*$/.test(childNode.data))hasText=true; |
| 146 | + for(let j=0;j<childNodes.length;j++){ |
| 147 | + let childNode=childNodes[j]; |
151 | 148 | if(childNode.tagName=="BR")cStr+="\r\n"; |
152 | 149 | else if(!/SCRIPT|STYLE/.test(childNode.tagName) && childNode.textContent)cStr+=childNode.textContent.replace(/\s*/," "); |
153 | 150 | } |
154 | | - if(hasText)rStr+=cStr; |
| 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; |
| 163 | + } |
155 | 164 | } |
156 | 165 | } |
157 | 166 | return rStr; |
|
0 commit comments