@@ -30,31 +30,32 @@ export default class BookmarkletFilter extends Filter {
30
30
mutePage : boolean ;
31
31
observer : MutationObserver ;
32
32
processMutationTarget : boolean ;
33
- processNode : ( node : HTMLElement | Document | ShadowRoot , wordlistId : number , stats ?: boolean ) => void ;
33
+ processNode : ( node : HTMLElement | Document | ShadowRoot , wordlistId : number , statsType ?: string | null ) => void ;
34
34
shadowObserver : MutationObserver ;
35
+ stats ?: Statistics ; // Bookmarklet: Not used
35
36
36
37
constructor ( ) {
37
38
super ( ) ;
38
39
this . extension = false ;
39
- this . audioWordlistId = 0 ;
40
+ this . audioWordlistId = Constants . ALL_WORDS_WORDLIST_ID ;
40
41
this . mutePage = false ;
41
42
this . processMutationTarget = false ;
42
43
}
43
44
44
- advancedReplaceText ( node , wordlistId : number , stats = true ) {
45
+ advancedReplaceText ( node , wordlistId : number , statsType : string | null = Constants . STATS_TYPE_TEXT ) {
45
46
if ( node . parentNode || node === document ) {
46
47
this . wordlists [ wordlistId ] . regExps . forEach ( ( regExp ) => {
47
48
// @ts -ignore: External library function
48
49
findAndReplaceDOMText ( node , { preset : 'prose' , find : regExp , replace : ( portion , match ) => {
49
50
if ( portion . index === 0 ) {
50
- return this . replaceText ( match [ 0 ] , wordlistId , stats ) ;
51
+ return this . replaceText ( match [ 0 ] , wordlistId , statsType ) ;
51
52
} else {
52
53
return '' ;
53
54
}
54
55
} } ) ;
55
56
} ) ;
56
57
} else {
57
- this . cleanText ( node , wordlistId , stats ) ;
58
+ this . cleanText ( node , wordlistId , statsType ) ;
58
59
}
59
60
}
60
61
@@ -150,31 +151,31 @@ export default class BookmarkletFilter extends Filter {
150
151
}
151
152
}
152
153
153
- cleanChildNode ( node , wordlistId : number , stats : boolean = true ) {
154
+ cleanChildNode ( node , wordlistId : number , statsType : string | null = Constants . STATS_TYPE_TEXT ) {
154
155
if ( node . nodeName ) {
155
156
if ( node . textContent && node . textContent . trim ( ) != '' ) {
156
- const result = this . replaceTextResult ( node . textContent , wordlistId , stats ) ;
157
+ const result = this . replaceTextResult ( node . textContent , wordlistId , statsType ) ;
157
158
if ( result . modified ) {
158
159
node . textContent = result . filtered ;
159
160
}
160
161
} else if ( node . nodeName == 'IMG' ) {
161
- if ( node . alt != '' ) { node . alt = this . replaceText ( node . alt , wordlistId , stats ) ; }
162
- if ( node . title != '' ) { node . title = this . replaceText ( node . title , wordlistId , stats ) ; }
162
+ if ( node . alt != '' ) { node . alt = this . replaceText ( node . alt , wordlistId , statsType ) ; }
163
+ if ( node . title != '' ) { node . title = this . replaceText ( node . title , wordlistId , statsType ) ; }
163
164
} else if ( node . shadowRoot ) {
164
- this . filterShadowRoot ( node . shadowRoot , wordlistId , stats ) ;
165
+ this . filterShadowRoot ( node . shadowRoot , wordlistId , statsType ) ;
165
166
}
166
167
}
167
168
}
168
169
169
- cleanNode ( node , wordlistId : number , stats : boolean = true ) {
170
+ cleanNode ( node , wordlistId : number , statsType : string | null = Constants . STATS_TYPE_TEXT ) {
170
171
if ( Page . isForbiddenNode ( node ) ) { return false ; }
171
- if ( node . shadowRoot ) { this . filterShadowRoot ( node . shadowRoot , wordlistId , stats ) ; }
172
+ if ( node . shadowRoot ) { this . filterShadowRoot ( node . shadowRoot , wordlistId , statsType ) ; }
172
173
if ( node . childNodes . length > 0 ) {
173
174
for ( let i = 0 ; i < node . childNodes . length ; i ++ ) {
174
- this . cleanNode ( node . childNodes [ i ] , wordlistId , stats ) ;
175
+ this . cleanNode ( node . childNodes [ i ] , wordlistId , statsType ) ;
175
176
}
176
177
} else {
177
- this . cleanChildNode ( node , this . wordlistId , stats ) ;
178
+ this . cleanChildNode ( node , this . wordlistId , statsType ) ;
178
179
}
179
180
}
180
181
@@ -209,30 +210,30 @@ export default class BookmarkletFilter extends Filter {
209
210
this . startObserving ( document ) ;
210
211
}
211
212
212
- cleanText ( node , wordlistId : number , stats : boolean = true ) {
213
+ cleanText ( node , wordlistId : number , statsType : string | null = Constants . STATS_TYPE_TEXT ) {
213
214
if ( Page . isForbiddenNode ( node ) ) { return false ; }
214
- if ( node . shadowRoot ) { this . filterShadowRoot ( node . shadowRoot , wordlistId , stats ) ; }
215
+ if ( node . shadowRoot ) { this . filterShadowRoot ( node . shadowRoot , wordlistId , statsType ) ; }
215
216
if ( node . childElementCount > 0 ) {
216
217
const treeWalker = document . createTreeWalker ( node , NodeFilter . SHOW_TEXT ) ;
217
218
while ( treeWalker . nextNode ( ) ) {
218
219
if ( treeWalker . currentNode . childNodes . length > 0 ) {
219
220
treeWalker . currentNode . childNodes . forEach ( ( childNode ) => {
220
- this . cleanText ( childNode , wordlistId , stats ) ;
221
+ this . cleanText ( childNode , wordlistId , statsType ) ;
221
222
} ) ;
222
223
} else {
223
224
if ( ! Page . isForbiddenNode ( treeWalker . currentNode ) ) {
224
- this . cleanChildNode ( treeWalker . currentNode , wordlistId , stats ) ;
225
+ this . cleanChildNode ( treeWalker . currentNode , wordlistId , statsType ) ;
225
226
}
226
227
}
227
228
}
228
229
} else {
229
- this . cleanChildNode ( node , wordlistId , stats ) ;
230
+ this . cleanChildNode ( node , wordlistId , statsType ) ;
230
231
}
231
232
}
232
233
233
- filterShadowRoot ( shadowRoot : ShadowRoot , wordlistId : number , stats : boolean = true ) {
234
+ filterShadowRoot ( shadowRoot : ShadowRoot , wordlistId : number , statsType : string | null = Constants . STATS_TYPE_TEXT ) {
234
235
this . shadowObserver . observe ( shadowRoot , observerConfig ) ;
235
- this . processNode ( shadowRoot , wordlistId , stats ) ;
236
+ this . processNode ( shadowRoot , wordlistId , statsType ) ;
236
237
}
237
238
238
239
init ( wordlistId : number | false = false ) {
0 commit comments