@@ -60,9 +60,17 @@ class ScribblehubParser extends Parser {
6060 let tags = [ ...dom . querySelectorAll ( selector ) ] ;
6161 return tags . map ( e => e . textContent . trim ( ) ) . join ( ", " ) ;
6262 }
63-
63+
6464 extractDescription ( dom ) {
65- return dom . querySelector ( "div [property='description']" ) . textContent . trim ( ) ;
65+ return this . extractDescriptionInternal ( dom ) . innerText . trim ( ) ;
66+ }
67+ // unwrap the description from the readmore that you may get on mobile
68+ extractDescriptionInternal ( dom ) {
69+ let desc = dom . querySelector ( ".wi_fic_desc" ) ;
70+ desc . querySelectorAll ( ".dots, .morelink" ) . forEach ( e => e . remove ( ) ) ;
71+ desc . querySelectorAll ( ".testhide" ) . forEach ( e => e . replaceWith ( ...e . childNodes ) ) ;
72+
73+ return desc ;
6674 }
6775
6876 findChapterTitle ( dom ) {
@@ -74,10 +82,67 @@ class ScribblehubParser extends Parser {
7482 }
7583
7684 preprocessRawDom ( webPageDom ) {
77- this . tagAuthorNotesBySelector ( webPageDom , ".wi_authornotes" , ".wi_news" ) ;
85+ let content = this . findContent ( webPageDom ) ;
86+
87+ this . tagAuthorNotesBySelector ( content , ".wi_authornotes, .wi_news" ) ;
88+
89+ // spoilers
90+ for ( let element of content . querySelectorAll ( ".sp-wrap" ) ) {
91+ element . querySelector ( ".sp-body>.spdiv" ) . remove ( ) ;
92+
93+ let details = webPageDom . createElement ( "details" ) ;
94+ let summary = webPageDom . createElement ( "summary" ) ;
95+ summary . append ( ...element . querySelector ( ".sp-head" ) . childNodes ) ;
96+ details . append ( summary ) ;
97+ details . append ( ...element . querySelector ( ".sp-body" ) . childNodes ) ;
98+
99+ element . replaceWith ( details ) ;
100+ }
101+
102+ // anouncements
103+ for ( let element of content . querySelectorAll ( ".wi_news_title" ) ) {
104+ element . setAttribute ( "style" , "font-weight: bold" ) ;
105+ element . querySelector ( ".fa-exclamation-triangle" ) . replaceWith ( "⚠" ) ;
106+ }
107+
108+ // author notes
109+ for ( let element of content . querySelectorAll ( ".p-avatar-wrap" ) ) {
110+ element . remove ( ) ;
111+ }
112+
78113 }
79114
80115 getInformationEpubItemChildNodes ( dom ) {
81- return [ ...dom . querySelectorAll ( "div.fic_row.details" ) ] ;
116+ function cleanTag ( tag , index , array ) {
117+ let out = tag . ownerDocument . createElement ( "a" ) ;
118+ out . setAttribute ( "href" , tag . getAttribute ( "href" ) ) ;
119+ out . innerText = tag . innerText ;
120+ return index < array . length - 1 ? [ out , ", " ] : [ out ] ;
121+ }
122+
123+ let info = [ ] ;
124+
125+ info . push ( dom . createElement ( "div" ) . innerHTML = "<p><b>Synopsis</b></p>" ) ;
126+ info . push ( ...this . extractDescriptionInternal ( dom ) . childNodes ) ;
127+
128+ let genre = dom . querySelectorAll ( ".wi_fic_genre a.fic_genre" ) ;
129+ if ( genre . length > 0 ) {
130+ info . push ( dom . createElement ( "div" ) . innerHTML = "<p><b>Genre</b></p>" ) ;
131+ info . push ( ...[ ...genre ] . flatMap ( cleanTag ) ) ;
132+ }
133+
134+ let fandom = dom . querySelectorAll ( ".wi_fic_genre a.stag" ) ;
135+ if ( fandom . length > 0 ) {
136+ info . push ( dom . createElement ( "div" ) . innerHTML = "<p><b>Fandom</b></p>" ) ;
137+ info . push ( ...[ ...fandom ] . flatMap ( cleanTag ) ) ;
138+ }
139+
140+ let tags = dom . querySelectorAll ( ".wi_fic_showtags a.stag" ) ;
141+ if ( tags . length > 0 ) {
142+ info . push ( dom . createElement ( "div" ) . innerHTML = "<p><b>Tags</b></p>" ) ;
143+ info . push ( ...[ ...tags ] . flatMap ( cleanTag ) ) ;
144+ }
145+
146+ return info ;
82147 }
83148}
0 commit comments