@@ -60,13 +60,14 @@ type BehaviorClass =
60
60
| typeof AutoScroll
61
61
| typeof Autoplay
62
62
| typeof AutoFetcher
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
64
| typeof BehaviorRunner < any , any > ;
64
65
65
66
type BehaviorInstance = InstanceType < BehaviorClass > ;
66
67
67
68
export class BehaviorManager {
68
69
autofetch ?: AutoFetcher ;
69
- behaviors : BehaviorInstance [ ] | null ;
70
+ behaviors : BehaviorInstance [ ] ;
70
71
loadedBehaviors : Record < string , BehaviorClass > ;
71
72
// eslint-disable-next-line @typescript-eslint/no-explicit-any
72
73
mainBehavior : BehaviorInstance | BehaviorRunner < any , any > | null ;
@@ -139,17 +140,17 @@ export class BehaviorManager {
139
140
140
141
if ( opts . autofetch ) {
141
142
void behaviorLog ( "Using AutoFetcher" ) ;
142
- this . behaviors ! . push ( this . autofetch ) ;
143
+ this . behaviors . push ( this . autofetch ) ;
143
144
}
144
145
145
146
if ( opts . autoplay ) {
146
147
void behaviorLog ( "Using Autoplay" ) ;
147
- this . behaviors ! . push ( new Autoplay ( this . autofetch , ! ! opts . startEarly ) ) ;
148
+ this . behaviors . push ( new Autoplay ( this . autofetch , ! ! opts . startEarly ) ) ;
148
149
}
149
150
150
151
if ( opts . autoclick ) {
151
152
void behaviorLog ( "Using AutoClick" ) ;
152
- this . behaviors ! . push (
153
+ this . behaviors . push (
153
154
new AutoClick ( opts . clickSelector || DEFAULT_CLICK_SELECTOR ) ,
154
155
) ;
155
156
}
@@ -160,6 +161,7 @@ export class BehaviorManager {
160
161
this . load ( behaviorClass ) ;
161
162
} catch ( e ) {
162
163
void behaviorLog (
164
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
163
165
`Failed to load custom behavior: ${ e } ${ behaviorClass } ` ,
164
166
) ;
165
167
}
@@ -186,6 +188,7 @@ export class BehaviorManager {
186
188
: { } ;
187
189
try {
188
190
this . mainBehavior = new BehaviorRunner (
191
+ // @ts -expect-error TODO figure out types here
189
192
siteBehaviorClass ,
190
193
siteSpecificOpts ,
191
194
) ;
@@ -208,7 +211,7 @@ export class BehaviorManager {
208
211
}
209
212
210
213
if ( this . mainBehavior ) {
211
- this . behaviors ! . push ( this . mainBehavior ) ;
214
+ this . behaviors . push ( this . mainBehavior ) ;
212
215
213
216
if ( this . mainBehavior instanceof BehaviorRunner ) {
214
217
return this . mainBehavior . behaviorProps . id ;
@@ -221,6 +224,7 @@ export class BehaviorManager {
221
224
load ( behaviorClass : unknown ) {
222
225
if ( typeof behaviorClass !== "function" ) {
223
226
void behaviorLog (
227
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
224
228
`Must pass a class object, got ${ behaviorClass } ` ,
225
229
"error" ,
226
230
) ;
@@ -279,7 +283,7 @@ export class BehaviorManager {
279
283
if (
280
284
this . mainBehavior &&
281
285
"awaitPageLoad" in this . mainBehavior &&
282
- ( this . mainBehavior as AbstractBehavior < any , any > ) . awaitPageLoad
286
+ ( this . mainBehavior as AbstractBehavior < unknown , unknown > ) . awaitPageLoad
283
287
) {
284
288
void behaviorLog ( "Waiting for custom page load via behavior" ) ;
285
289
// @ts -expect-error TODO why isn't `log` passed in here? It seems like functions expect it to be
@@ -304,18 +308,21 @@ export class BehaviorManager {
304
308
305
309
await awaitLoad ( ) ;
306
310
307
- this . behaviors ! . forEach ( ( x ) => {
308
- const id = x . id || x . constructor . id || "(Unnamed)" ;
309
- behaviorLog ( "Starting behavior: " + id , "debug" ) ;
310
- x . start ( ) ;
311
+ this . behaviors . forEach ( ( x ) => {
312
+ const id =
313
+ ( x as unknown as typeof AbstractBehavior < unknown > ) . id ||
314
+ ( x . constructor as unknown as typeof AbstractBehavior < unknown > ) . id ||
315
+ "(Unnamed)" ;
316
+ void behaviorLog ( "Starting behavior: " + id , "debug" ) ;
317
+ "start" in x && void x . start ( ) ;
311
318
} ) ;
312
319
313
320
this . started = true ;
314
321
315
322
await sleep ( 500 ) ;
316
323
317
324
const allBehaviors = Promise . allSettled (
318
- this . behaviors . map ( ( x ) => x . done ( ) ) ,
325
+ this . behaviors . map ( async ( x ) => "done" in x && x . done ( ) ) ,
319
326
) ;
320
327
321
328
if ( this . timeout ) {
@@ -325,44 +332,48 @@ export class BehaviorManager {
325
332
) ;
326
333
await Promise . race ( [ allBehaviors , sleep ( this . timeout ) ] ) ;
327
334
} else {
328
- behaviorLog ( "Waiting for behaviors to finish" , "debug" ) ;
335
+ void behaviorLog ( "Waiting for behaviors to finish" , "debug" ) ;
329
336
await allBehaviors ;
330
337
}
331
338
332
- behaviorLog ( "All Behaviors Done for " + self . location . href , "debug" ) ;
339
+ void behaviorLog ( "All Behaviors Done for " + self . location . href , "debug" ) ;
333
340
334
- if ( this . mainBehavior && this . mainBehaviorClass . cleanup ) {
341
+ if ( this . mainBehavior && "cleanup" in this . mainBehavior ) {
335
342
this . mainBehavior . cleanup ( ) ;
336
343
}
337
344
}
338
345
339
- async runOne ( name , behaviorOpts = { } ) {
346
+ async runOne ( name : string , behaviorOpts = { } ) {
340
347
const siteBehaviorClass = siteBehaviors . find ( ( b ) => b . name === name ) ;
341
348
if ( typeof siteBehaviorClass === "undefined" ) {
342
349
console . error ( `No behavior of name ${ name } found` ) ;
343
350
return ;
344
351
}
345
352
//const behavior = new siteBehaviorClass(behaviorOpts);
346
- const behavior = new BehaviorRunner ( siteBehaviorClass , behaviorOpts ) ;
353
+ const behavior = new BehaviorRunner (
354
+ // @ts -expect-error TODO figure out types here
355
+ siteBehaviorClass ,
356
+ behaviorOpts ,
357
+ ) ;
347
358
behavior . start ( ) ;
348
359
console . log ( `Running behavior: ${ name } ` ) ;
349
360
await behavior . done ( ) ;
350
361
console . log ( `Behavior ${ name } completed` ) ;
351
362
}
352
363
353
364
pause ( ) {
354
- behaviorLog ( "Pausing Main Behavior" + this . mainBehaviorClass . name ) ;
355
- this . behaviors . forEach ( ( x ) => x . pause ( ) ) ;
365
+ void behaviorLog ( "Pausing Main Behavior" + this . mainBehaviorClass . name ) ;
366
+ this . behaviors . forEach ( ( x ) => "pause" in x && x . pause ( ) ) ;
356
367
}
357
368
358
369
unpause ( ) {
359
370
// behaviorLog("Unpausing Main Behavior: " + this.mainBehaviorClass.name);
360
- this . behaviors . forEach ( ( x ) => x . unpause ( ) ) ;
371
+ this . behaviors . forEach ( ( x ) => "pause" in x && x . unpause ( ) ) ;
361
372
}
362
373
363
- doAsyncFetch ( url ) {
364
- behaviorLog ( "Queueing Async Fetch Url: " + url ) ;
365
- return this . autofetch . queueUrl ( url , true ) ;
374
+ doAsyncFetch ( url : string ) {
375
+ void behaviorLog ( "Queueing Async Fetch Url: " + url ) ;
376
+ return this . autofetch ! . queueUrl ( url , true ) ;
366
377
}
367
378
368
379
isInTopFrame ( ) {
@@ -391,9 +402,10 @@ export class BehaviorManager {
391
402
392
403
const urls = new Set < string > ( ) ;
393
404
394
- document . querySelectorAll ( selector ) . forEach ( ( elem : any ) => {
405
+ document . querySelectorAll ( selector ) . forEach ( ( elem ) => {
395
406
// first, try property, unless attrOnly is set
396
- let value = ! attrOnly ? elem [ extractName ] : null ;
407
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
408
+ let value = ! attrOnly ? ( elem as any ) [ extractName ] : null ;
397
409
if ( ! value ) {
398
410
value = elem . getAttribute ( extractName ) ;
399
411
}
0 commit comments