@@ -224,7 +224,7 @@ async function fetchData(location, options = {}) {
224
224
if ( result . error ) {
225
225
await handleError ( result ) ;
226
226
} else {
227
- if ( location === "torn" && ! options . silent && SCRIPT_TYPE === "BACKGROUND" ) {
227
+ if ( isTornAPICall ( location ) && ! options . silent && SCRIPT_TYPE === "BACKGROUND" ) {
228
228
await getBadgeText ( )
229
229
. then ( async ( value ) => {
230
230
if ( value === "error" ) await setBadge ( "default" ) ;
@@ -255,7 +255,7 @@ async function fetchData(location, options = {}) {
255
255
const isLocal = false ;
256
256
const code = CUSTOM_API_ERROR . CANCELLED ;
257
257
258
- if ( location === "torn" && ! options . silent && SCRIPT_TYPE === "BACKGROUND" ) {
258
+ if ( isTornAPICall ( location ) && ! options . silent && SCRIPT_TYPE === "BACKGROUND" ) {
259
259
await ttStorage . change ( { api : { torn : { online : false , error } } } ) ;
260
260
await setBadge ( "error" ) ;
261
261
}
@@ -276,12 +276,12 @@ async function fetchData(location, options = {}) {
276
276
}
277
277
}
278
278
279
- if ( location === "torn" && ! options . silent && SCRIPT_TYPE === "BACKGROUND" ) {
279
+ if ( isTornAPICall ( location ) && ! options . silent && SCRIPT_TYPE === "BACKGROUND" ) {
280
280
await ttStorage . change ( { api : { torn : { online : false , error } } } ) ;
281
281
await setBadge ( "error" ) ;
282
282
}
283
283
reject ( { error, isLocal, code } ) ;
284
- } else if ( location === "torn" ) {
284
+ } else if ( isTornAPICall ( location ) ) {
285
285
let error , online ;
286
286
287
287
if ( result . error instanceof HTTPException ) {
@@ -310,6 +310,10 @@ async function fetchData(location, options = {}) {
310
310
} ) ;
311
311
}
312
312
313
+ function isTornAPICall ( location ) {
314
+ return [ "torn" , "tornv2" ] . includes ( location ) ;
315
+ }
316
+
313
317
function checkAPIPermission ( key ) {
314
318
return new Promise ( ( resolve , reject ) => {
315
319
fetchData ( "torn" , { section : "key" , selections : [ "info" ] , key, silent : true } )
0 commit comments