|
4 | 4 | // @name:zh-TW 懶人小説下載器 |
5 | 5 | // @name:ja 怠惰者小説ダウンロードツール |
6 | 6 | // @namespace hoothin |
7 | | -// @version 1.08 |
| 7 | +// @version 1.09 |
8 | 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文檔 |
|
31 | 31 | case "zh-CN": |
32 | 32 | i18n={ |
33 | 33 | fetch:"开始下载小说或其他【Ctrl+F9】", |
34 | | - info:"本文是使用懒人小说下载器(DownloadAllContent)脚本下载的" |
| 34 | + info:"本文是使用懒人小说下载器(DownloadAllContent)脚本下载的", |
| 35 | + error:"该段内容获取失败" |
35 | 36 | }; |
36 | 37 | break; |
37 | 38 | default: |
38 | 39 | i18n={ |
39 | 40 | fetch:"Download All Content[Ctrl+F9]", |
40 | | - info:"The TXT is downloaded by 'DownloadAllContent'" |
| 41 | + info:"The TXT is downloaded by 'DownloadAllContent'", |
| 42 | + error:"Failed in downloading current chapter" |
41 | 43 | }; |
42 | 44 | break; |
43 | 45 | } |
|
98 | 100 | } |
99 | 101 |
|
100 | 102 | function getPageContent(doc){ |
101 | | - if(!doc)return "该段内容获取失败"; |
| 103 | + if(!doc)return i18n.error; |
102 | 104 | var i,j,k,rStr="",pageData=(doc.body?doc.body:doc).cloneNode(true),delList=[]; |
103 | 105 | [].forEach.call(pageData.querySelectorAll("script,style,link"),function(item){delList.push(item);}); |
104 | 106 | [].forEach.call(delList,function(item){item.parentNode.removeChild(item);}); |
|
107 | 109 | let content=contents[i],hasText=false,allSingle=true,item; |
108 | 110 | for(j=content.childNodes.length-1;j>=0;j--){ |
109 | 111 | item=content.childNodes[j]; |
110 | | - if(item.nodeType==3 && /^\s*$/.test(item.data)) |
| 112 | + if((item.nodeType==3 && /^\s*$/.test(item.data)) || (item.tagName=="FONT" && item.className=="jammer") || (item.style && item.style.display=="none")) |
111 | 113 | item.parentNode.removeChild(item); |
112 | 114 | } |
113 | 115 | [].forEach.call(content.childNodes,function(item){ |
|
155 | 157 | } |
156 | 158 | } |
157 | 159 | } |
158 | | - if(!largestContent)return "该段内容获取失败"; |
| 160 | + if(!largestContent)return i18n.error; |
159 | 161 | var childlist=pageData.querySelectorAll(largestContent.tagName+(largestContent.className?"."+largestContent.className.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, '.'):"")); |
160 | 162 | function getRightStr(ele, noTextEnable){ |
161 | 163 | let childNodes=ele.childNodes,cStr="\r\n",hasText=false; |
|
165 | 167 | if(childNode.textContent){ |
166 | 168 | cStr+=childNode.textContent.replace(/ +/g," ").replace(/([^\r]|^)\n([^\r]|$)/g,"$1\r\n$2"); |
167 | 169 | } |
168 | | - if(childNode.nodeType!=3)cStr+="\r\n"; |
| 170 | + if(childNode.nodeType!=3 && !/^(I|A|STRONG|B|FONT)$/.test(childNode.tagName))cStr+="\r\n"; |
169 | 171 | } |
170 | 172 | if(hasText || noTextEnable || ele==largestContent)rStr+=cStr+"\r\n"; |
171 | 173 | } |
|
0 commit comments