|
4 | 4 | // @name:zh-TW 懶人小説下載器 |
5 | 5 | // @name:ja 怠惰者小説ダウンロードツール |
6 | 6 | // @namespace hoothin |
7 | | -// @version 0.6 |
| 7 | +// @version 0.7 |
8 | 8 | // @description Fetch and download main content on current page |
9 | 9 | // @description:zh-CN 通用网站内容抓取工具,可批量抓取小说、论坛内容等并保存为TXT文档 |
10 | 10 | // @description:zh-TW 通用網站內容抓取工具,可批量抓取小說、論壇內容等並保存為TXT文檔 |
|
85 | 85 | } |
86 | 86 | for(let i=0;i<aEles.length;i++){ |
87 | 87 | let aTag=aEles[i]; |
| 88 | + var contentType=document.querySelector("meta[http-equiv=Content-Type]"); |
88 | 89 | GM_xmlhttpRequest({ |
89 | 90 | method: 'GET', |
90 | 91 | url: aTag.href, |
| 92 | + overrideMimeType:contentType?contentType.content:null, |
91 | 93 | onload: function(result) { |
92 | 94 | var doc = getDocEle(result.responseText); |
93 | 95 | if (!doc) { |
94 | 96 | return; |
95 | 97 | } |
96 | | - var contentType=doc.querySelector("meta[http-equiv=Content-Type]"); |
97 | | - if(contentType && !/utf\-?8/i.test(contentType.content)){ |
98 | | - GM_xmlhttpRequest({ |
99 | | - method: 'GET', |
100 | | - url: aTag.href, |
101 | | - overrideMimeType:contentType.content, |
102 | | - onload: function(result) { |
103 | | - var doc = getDocEle(result.responseText); |
104 | | - if (!doc) { |
105 | | - return; |
106 | | - } |
107 | | - processDoc(i, aTag, doc); |
108 | | - } |
109 | | - }); |
110 | | - }else{ |
111 | | - processDoc(i, aTag, doc); |
112 | | - } |
| 98 | + processDoc(i, aTag, doc); |
113 | 99 | } |
114 | 100 | }); |
115 | 101 | } |
|
139 | 125 | } |
140 | 126 | } |
141 | 127 | var childlist=pageData.querySelectorAll(largestContent.tagName); |
| 128 | + function getRightStr(ele, noTextEnable){ |
| 129 | + let childNodes=ele.childNodes,cStr="\r\n",hasText=false; |
| 130 | + for(let j=0;j<childNodes.length;j++){ |
| 131 | + let childNode=childNodes[j]; |
| 132 | + if(childNode.nodeType==3 && childNode.data && !/^\s*$/.test(childNode.data))hasText=true; |
| 133 | + if(childNode.tagName=="BR")cStr+="\r\n"; |
| 134 | + else if(!/SCRIPT|STYLE/.test(childNode.tagName) && childNode.textContent)cStr+=childNode.textContent.replace(/\s*/," "); |
| 135 | + } |
| 136 | + if(hasText || noTextEnable)rStr+=cStr; |
| 137 | + } |
142 | 138 | for(i=0;i<childlist.length;i++){ |
143 | 139 | var child=childlist[i]; |
144 | | - if(largestContent.className && largestContent.className==child.className){ |
145 | | - let childNodes=child.childNodes,cStr="\r\n",hasText=false; |
146 | | - for(let j=0;j<childNodes.length;j++){ |
147 | | - let childNode=childNodes[j]; |
148 | | - if(childNode.tagName=="BR")cStr+="\r\n"; |
149 | | - else if(!/SCRIPT|STYLE/.test(childNode.tagName) && childNode.textContent)cStr+=childNode.textContent.replace(/\s*/," "); |
150 | | - } |
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; |
| 140 | + if(getDepth(child)==getDepth(largestContent)){ |
| 141 | + if(largestContent.className && largestContent.className==child.className){ |
| 142 | + getRightStr(child, true); |
| 143 | + }else { |
| 144 | + getRightStr(child, false); |
163 | 145 | } |
164 | 146 | } |
165 | 147 | } |
|
0 commit comments