|
4 | 4 | // @name:zh-TW 懶人小説下載器 |
5 | 5 | // @name:ja 怠惰者小説ダウンロードツール |
6 | 6 | // @namespace hoothin |
7 | | -// @version 1.05 |
8 | | -// @description Fetch and download main content on current page |
| 7 | +// @version 1.06 |
| 8 | +// @description Fetch and download main content on current page,provide special support for chinese novel |
9 | 9 | // @description:zh-CN 通用网站内容抓取工具,可批量抓取小说、论坛内容等并保存为TXT文档 |
10 | 10 | // @description:zh-TW 通用網站內容抓取工具,可批量抓取小說、論壇內容等並保存為TXT文檔 |
11 | 11 | // @description:ja ユニバーサルサイトコンテンツクロールツール、クロール、フォーラム内容など |
|
14 | 14 | // @grant GM_xmlhttpRequest |
15 | 15 | // @grant GM_registerMenuCommand |
16 | 16 | // @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js |
17 | | -// @updateURL https://greasyfork.org/scripts/25068/code/DownloadAllContent.user.js |
18 | | -// @downloadURL https://greasyfork.org/scripts/25068/code/DownloadAllContent.user.js |
19 | 17 | // @license MIT License |
20 | 18 | // @compatible chrome |
21 | 19 | // @compatible firefox |
|
103 | 101 | } |
104 | 102 |
|
105 | 103 | function getPageContent(doc){ |
106 | | - var i,j,rStr="",pageData=(doc.body?doc.body:doc).cloneNode(true),delList=[]; |
| 104 | + var i,j,k,rStr="",pageData=(doc.body?doc.body:doc).cloneNode(true),delList=[]; |
107 | 105 | [].forEach.call(pageData.querySelectorAll("script,style,link"),function(item){delList.push(item);}); |
108 | 106 | [].forEach.call(delList,function(item){item.parentNode.removeChild(item);}); |
109 | 107 | var largestContent,contents=pageData.querySelectorAll("span,div,article,p,td"); |
|
121 | 119 | if(content.childNodes.length>1){ |
122 | 120 | for(j=0;j<content.childNodes.length;j++){ |
123 | 121 | item=content.childNodes[j]; |
124 | | - if(item.nodeType==1 && item.firstChild && item.firstChild.nodeType!=3){ |
125 | | - allSingle=false; |
126 | | - break; |
| 122 | + if(item.nodeType==1){ |
| 123 | + for(k=0;k<item.childNodes.length;k++){ |
| 124 | + var childNode=item.childNodes[k]; |
| 125 | + if(childNode.nodeType!=3 && !/^(I|A|STRONG|B|FONT|BR)$/.test(childNode.tagName)){ |
| 126 | + allSingle=false; |
| 127 | + break; |
| 128 | + } |
| 129 | + } |
| 130 | + if(!allSingle)break; |
| 131 | + delList=[]; |
| 132 | + [].forEach.call(item.childNodes,function(n){if((n.nodeType==3 && /^\s*$/.test(n.data)) || (n.nodeType==1 && /^\s*$/.test(n.textContent)))delList.push(n);}); |
| 133 | + [].forEach.call(delList,function(n){n.parentNode.removeChild(n);}); |
127 | 134 | } |
128 | 135 | } |
129 | 136 | }else{ |
|
159 | 166 | if(childNode.tagName=="BR")cStr+="\r\n"; |
160 | 167 | else if(childNode.textContent)cStr+=childNode.textContent.replace(/ +/g," ").replace(/([^\r]|^)\n([^\r]|$)/g,"$1\r\n$2"); |
161 | 168 | } |
162 | | - if(hasText || noTextEnable)rStr+=cStr+"\r\n"; |
| 169 | + if(hasText || noTextEnable || ele==largestContent)rStr+=cStr+"\r\n"; |
163 | 170 | } |
164 | 171 | for(i=0;i<childlist.length;i++){ |
165 | 172 | var child=childlist[i]; |
|
0 commit comments