diff --git a/src/common/ScriptInjector.ts b/src/common/ScriptInjector.ts index 8ff723ae..05f87ab7 100644 --- a/src/common/ScriptInjector.ts +++ b/src/common/ScriptInjector.ts @@ -193,7 +193,7 @@ class _ScriptInjector { params: Record = {}, tabId: number | null = null ): Promise { - if (!url) { + if (!url && Shared.manifestVersion !== 3) { return null; } @@ -206,6 +206,8 @@ class _ScriptInjector { target: { tabId }, func: Shared.functionsToInject[id], args: [params], + // @ts-expect-error This is a newer value, so it's missing from the types. + world: 'MAIN', }) .then((results) => { const value = results[0].result as T | null; @@ -225,6 +227,8 @@ class _ScriptInjector { target: { tabId }, func: Shared.functionsToInject[id], args: [params], + // @ts-expect-error This is a newer value, so it's missing from the types. + world: 'MAIN', }); value = results[0].result as T | null; } else { diff --git a/src/common/ScrobbleParser.ts b/src/common/ScrobbleParser.ts index 2db41054..8b810328 100644 --- a/src/common/ScrobbleParser.ts +++ b/src/common/ScrobbleParser.ts @@ -83,7 +83,7 @@ export abstract class ScrobbleParser { * Below are the methods that can be used to parse the playback. Generic methods do not need to be overridden in the child class, as they should work out-of-the-box. If one method fails, the next one is attempted, in the order listed. * * 1. **video player:** generic method, based on `videoPlayerSelector`, which can be specified through the options - * 2. **injected script:** specific method (requires adding a function to the `{serviceId}-playback` key in `Shared.functionsToInject` e.g. `netflix-playback`) + * 2. **injected script:** specific method (requires adding a function to the `{serviceId}-playback` key in `Shared.functionsToInject` at the `{serviceName}Api.ts` file e.g. `netflix-playback` at `NetflixApi.ts`) * 3. **DOM:** specific method (requires override) * 4. **custom:** specific method (requires override) */ @@ -193,7 +193,7 @@ export abstract class ScrobbleParser { * Below are the methods that can be used to parse the item. Generic methods do not need to be overridden in the child class, as they should work out-of-the-box. If one method fails, the next one is attempted, in the order listed. * * 1. **API:** generic method, but requires a non-null return from `parseItemId` and the implementation of `*Api#getItem` - * 2. **injected script:** specific method (requires adding a function to the `{serviceId}-item` key in `Shared.functionsToInject` e.g. `netflix-item`) + * 2. **injected script:** specific method (requires adding a function to the `{serviceId}-item` key in `Shared.functionsToInject` at the `{serviceName}Api.ts` file e.g. `netflix-item` at `NetflixApi.ts`) * 3. **DOM:** specific method (requires override) * 4. **custom:** specific method (requires override) */ @@ -254,7 +254,7 @@ export abstract class ScrobbleParser { * Below are the methods that can be used to parse the item ID. Generic methods do not need to be overridden in the child class, as they should work out-of-the-box. If one method fails, the next one is attempted, in the order listed. * * 1. **URL:** generic method, based on `watchingUrlRegex`, which can be specified through the options - * 2. **injected script:** specific method (requires adding a function to the `{serviceId}-item-id` key in `Shared.functionsToInject` e.g. `netflix-item-id`) + * 2. **injected script:** specific method (requires adding a function to the `{serviceId}-item-id` key in `Shared.functionsToInject` at the `{serviceName}Api.ts` file e.g. `netflix-item-id` at `NetflixApi.ts`) * 3. **DOM:** specific method (requires override) * 4. **custom:** specific method (requires override) */ diff --git a/src/services/nrk/NrkApi.ts b/src/services/nrk/NrkApi.ts index b5714b30..3296ea33 100644 --- a/src/services/nrk/NrkApi.ts +++ b/src/services/nrk/NrkApi.ts @@ -1,6 +1,7 @@ import { NrkService } from '@/nrk/NrkService'; import { ServiceApi } from '@apis/ServiceApi'; import { Requests, withHeaders } from '@common/Requests'; +import { Shared } from '@common/Shared'; import { Utils } from '@common/Utils'; import { BaseItemValues, @@ -333,4 +334,16 @@ class _NrkApi extends ServiceApi { } } +Shared.functionsToInject[`${NrkService.id}-item-id`] = () => { + let itemId: string | null = null; + const { player } = window; + if (player) { + const playbackSession = player.getPlaybackSession(); + if (playbackSession) { + itemId = playbackSession.mediaItem?.id ?? null; + } + } + return itemId; +}; + export const NrkApi = new _NrkApi(); diff --git a/src/services/nrk/NrkParser.ts b/src/services/nrk/NrkParser.ts index 30dd4161..dd9ba7ca 100644 --- a/src/services/nrk/NrkParser.ts +++ b/src/services/nrk/NrkParser.ts @@ -1,6 +1,5 @@ import { NrkApi } from '@/nrk/NrkApi'; import { ScrobbleParser } from '@common/ScrobbleParser'; -import { Shared } from '@common/Shared'; class _NrkParser extends ScrobbleParser { constructor() { @@ -8,16 +7,4 @@ class _NrkParser extends ScrobbleParser { } } -Shared.functionsToInject[`${NrkApi.id}-item-id`] = () => { - let itemId: string | null = null; - const { player } = window; - if (player) { - const playbackSession = player.getPlaybackSession(); - if (playbackSession) { - itemId = playbackSession.mediaItem?.id ?? null; - } - } - return itemId; -}; - export const NrkParser = new _NrkParser();