@@ -12,7 +12,7 @@ import {
12
12
addLink ,
13
13
checkToJsonOverride ,
14
14
} from "./lib/utils" ;
15
- import { type Behavior , BehaviorRunner } from "./lib/behavior" ;
15
+ import { AbstractBehavior , type Behavior , BehaviorRunner } from "./lib/behavior" ;
16
16
import * as Lib from "./lib/utils" ;
17
17
18
18
import siteBehaviors from "./site" ;
@@ -27,10 +27,10 @@ interface BehaviorManagerOpts {
27
27
autoplay ?: boolean ;
28
28
autoscroll ?: boolean ;
29
29
autoclick ?: boolean ;
30
- log ?: ( ( ...message : string [ ] ) => void ) | string | false ;
31
- siteSpecific ?: boolean | object ;
30
+ log ?: ( ( ...message : string [ ] ) => void ) | keyof typeof self | false ;
31
+ siteSpecific ?: boolean | Record < string , unknown > ;
32
32
timeout ?: number ;
33
- fetchHeaders ?: object | null ;
33
+ fetchHeaders ?: Record < string , string > | null ;
34
34
startEarly ?: boolean | null ;
35
35
clickSelector ?: string ;
36
36
}
@@ -54,12 +54,14 @@ const DEFAULT_CLICK_SELECTOR = "a";
54
54
const DEFAULT_LINK_SELECTOR = "a[href]" ;
55
55
const DEFAULT_LINK_EXTRACT = "href" ;
56
56
57
+ type TODOBehaviorClass = AbstractBehavior < unknown , unknown , unknown > ;
58
+
57
59
export class BehaviorManager {
58
- autofetch : AutoFetcher ;
59
- behaviors : any [ ] ;
60
- loadedBehaviors : any ;
60
+ autofetch ? : AutoFetcher ;
61
+ behaviors : TODOBehaviorClass [ ] | null ;
62
+ loadedBehaviors : TODOBehaviorClass ;
61
63
mainBehavior : Behavior | BehaviorRunner < unknown , unknown , unknown > | null ;
62
- mainBehaviorClass : any ;
64
+ mainBehaviorClass : TODOBehaviorClass ;
63
65
inited : boolean ;
64
66
started : boolean ;
65
67
timeout ?: number ;
@@ -79,13 +81,13 @@ export class BehaviorManager {
79
81
selector : DEFAULT_LINK_SELECTOR ,
80
82
extractName : DEFAULT_LINK_EXTRACT ,
81
83
} ;
82
- behaviorLog ( "Loaded behaviors for: " + self . location . href ) ;
84
+ void behaviorLog ( "Loaded behaviors for: " + self . location . href ) ;
83
85
}
84
86
85
87
init (
86
88
opts : BehaviorManagerOpts = DEFAULT_OPTS ,
87
89
restart = false ,
88
- customBehaviors : any [ ] = null ,
90
+ customBehaviors : TODOBehaviorClass [ ] | null = null ,
89
91
) {
90
92
if ( this . inited && ! restart ) {
91
93
return ;
@@ -94,6 +96,7 @@ export class BehaviorManager {
94
96
this . inited = true ;
95
97
this . opts = opts ;
96
98
99
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
97
100
if ( ! self . window ) {
98
101
return ;
99
102
}
@@ -119,22 +122,22 @@ export class BehaviorManager {
119
122
this . autofetch = new AutoFetcher (
120
123
! ! opts . autofetch ,
121
124
opts . fetchHeaders ,
122
- opts . startEarly ,
125
+ ! ! opts . startEarly ,
123
126
) ;
124
127
125
128
if ( opts . autofetch ) {
126
- behaviorLog ( "Using AutoFetcher" ) ;
127
- this . behaviors . push ( this . autofetch ) ;
129
+ void behaviorLog ( "Using AutoFetcher" ) ;
130
+ this . behaviors ! . push ( this . autofetch ) ;
128
131
}
129
132
130
133
if ( opts . autoplay ) {
131
- behaviorLog ( "Using Autoplay" ) ;
132
- this . behaviors . push ( new Autoplay ( this . autofetch , opts . startEarly ) ) ;
134
+ void behaviorLog ( "Using Autoplay" ) ;
135
+ this . behaviors ! . push ( new Autoplay ( this . autofetch , ! ! opts . startEarly ) ) ;
133
136
}
134
137
135
138
if ( opts . autoclick ) {
136
- behaviorLog ( "Using AutoClick" ) ;
137
- this . behaviors . push (
139
+ void behaviorLog ( "Using AutoClick" ) ;
140
+ this . behaviors ! . push (
138
141
new AutoClick ( opts . clickSelector || DEFAULT_CLICK_SELECTOR ) ,
139
142
) ;
140
143
}
@@ -144,7 +147,9 @@ export class BehaviorManager {
144
147
try {
145
148
this . load ( behaviorClass ) ;
146
149
} catch ( e ) {
147
- behaviorLog ( `Failed to load custom behavior: ${ e } ${ behaviorClass } ` ) ;
150
+ void behaviorLog (
151
+ `Failed to load custom behavior: ${ e } ${ behaviorClass } ` ,
152
+ ) ;
148
153
}
149
154
}
150
155
}
@@ -157,11 +162,11 @@ export class BehaviorManager {
157
162
const opts = this . opts ;
158
163
let siteMatch = false ;
159
164
160
- if ( opts . siteSpecific ) {
165
+ if ( opts ? .siteSpecific ) {
161
166
for ( const name in this . loadedBehaviors ) {
162
167
const siteBehaviorClass = this . loadedBehaviors [ name ] ;
163
168
if ( siteBehaviorClass . isMatch ( ) ) {
164
- behaviorLog ( "Using Site-Specific Behavior: " + name ) ;
169
+ void behaviorLog ( "Using Site-Specific Behavior: " + name ) ;
165
170
this . mainBehaviorClass = siteBehaviorClass ;
166
171
const siteSpecificOpts =
167
172
typeof opts . siteSpecific === "object"
@@ -173,7 +178,10 @@ export class BehaviorManager {
173
178
siteSpecificOpts ,
174
179
) ;
175
180
} catch ( e ) {
176
- behaviorLog ( { msg : e . toString ( ) , siteSpecific : true } , "error" ) ;
181
+ void behaviorLog (
182
+ { msg : ( e as Error ) . toString ( ) , siteSpecific : true } ,
183
+ "error" ,
184
+ ) ;
177
185
}
178
186
siteMatch = true ;
179
187
break ;
0 commit comments