|
4 | 4 | // @name:zh-TW 懶人小説下載器 |
5 | 5 | // @name:ja 怠惰者小説ダウンロードツール |
6 | 6 | // @namespace hoothin |
7 | | -// @version 1.23 |
| 7 | +// @version 1.25 |
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文檔 |
|
121 | 121 |
|
122 | 122 | function getPageContent(doc){ |
123 | 123 | if(!doc)return i18n.error; |
| 124 | + [].forEach.call(doc.querySelectorAll("span,div"),function(item){ |
| 125 | + var thisStyle=doc.defaultView.getComputedStyle(item); |
| 126 | + if(thisStyle && (thisStyle.display=="none"||thisStyle.fontSize=="0px")) |
| 127 | + item.parentNode.removeChild(item); |
| 128 | + }); |
124 | 129 | var i,j,k,rStr="",pageData=(doc.body?doc.body:doc).cloneNode(true),delList=[]; |
125 | | - [].forEach.call(pageData.querySelectorAll("script,style,link,img,noscript"),function(item){delList.push(item);}); |
126 | | - [].forEach.call(delList,function(item){item.parentNode.removeChild(item);}); |
127 | 130 | [].forEach.call(pageData.querySelectorAll("font.jammer"),function(item){ |
128 | 131 | item.parentNode.removeChild(item); |
129 | 132 | }); |
|
133 | 136 | item.parentNode.removeChild(item); |
134 | 137 | }); |
135 | 138 | } |
136 | | - [].forEach.call(pageData.querySelectorAll("span"),function(item){ |
137 | | - if(item.style && item.style.display=="none") |
138 | | - item.parentNode.removeChild(item); |
139 | | - }); |
| 139 | + [].forEach.call(pageData.querySelectorAll("script,style,link,img,noscript"),function(item){delList.push(item);}); |
| 140 | + [].forEach.call(delList,function(item){item.parentNode.removeChild(item);}); |
140 | 141 | var largestContent,contents=pageData.querySelectorAll("span,div,article,p,td"),largestNum=0; |
141 | 142 | for(i=0;i<contents.length;i++){ |
142 | 143 | let content=contents[i],hasText=false,allSingle=true,item,curNum=0; |
|
187 | 188 | } |
188 | 189 | } |
189 | 190 | if(!largestContent)return i18n.error; |
190 | | - var childlist=pageData.querySelectorAll(largestContent.tagName+(largestContent.className?"."+largestContent.className.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, '.'):"")); |
| 191 | + var childlist=pageData.querySelectorAll(largestContent.tagName);//+(largestContent.className?"."+largestContent.className.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, '.'):"")); |
191 | 192 | function getRightStr(ele, noTextEnable){ |
192 | 193 | let childNodes=ele.childNodes,cStr="\r\n",hasText=false; |
193 | 194 | for(let j=0;j<childNodes.length;j++){ |
|
206 | 207 | for(i=0;i<childlist.length;i++){ |
207 | 208 | var child=childlist[i]; |
208 | 209 | if(getDepth(child)==getDepth(largestContent)){ |
209 | | - if(largestContent.className && largestContent.className==child.className){ |
| 210 | + if((largestContent.className && largestContent.className==child.className)||largestContent.parentNode ==child.parentNode){ |
210 | 211 | getRightStr(child, true); |
211 | 212 | }else { |
212 | 213 | getRightStr(child, false); |
|
247 | 248 | break; |
248 | 249 | } |
249 | 250 | } |
250 | | - if(!has && aEle.href && /^http/i.test(aEle.href) && /PART\b|Prologue|分卷|Chapter\s*\d+|第.+[章|节|回|卷|折|篇|幕|集]|^序$|序\s*言|序\s*章|前\s*言|引\s*言|引\s*子|摘\s*要|楔\s*子|契\s*子|后\s*记|附\s*言|结\s*语|[\d|〇|零|一|二|三|四|五|六|七|八|九|十|百|千|万|萬|-]+(、|)|\.)/i.test(aEle.innerText)){ |
| 251 | + if(!has && aEle.href && /^http/i.test(aEle.href) && /PART\b|Prologue|-\d+|分卷|Chapter\s*\d+|第.+[章|节|回|卷|折|篇|幕|集]|^序$|序\s*言|序\s*章|前\s*言|引\s*言|引\s*子|摘\s*要|楔\s*子|契\s*子|后\s*记|附\s*言|结\s*语|[\d|〇|零|一|二|三|四|五|六|七|八|九|十|百|千|万|萬|-]+(、|)|\.)/i.test(aEle.innerText)){ |
251 | 252 | list.push(aEle); |
252 | 253 | } |
253 | 254 | } |
|
0 commit comments