From 49246fee61281137fada759be81fbbff6ceab93d Mon Sep 17 00:00:00 2001 From: sua yoo Date: Tue, 28 Nov 2023 13:12:29 -0800 Subject: [PATCH] chore: convert sw.js to typescript --- src/index.d.ts | 1 + src/{sw.js => sw.ts} | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) rename src/{sw.js => sw.ts} (63%) diff --git a/src/index.d.ts b/src/index.d.ts index 17f1aa6..5dfb0f7 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,4 +1,5 @@ declare module "*.svg"; +declare module "*.html"; declare const __SW_NAME__: string; declare const __HELPER_PROXY__: string; declare const __GDRIVE_CLIENT_ID__: string; diff --git a/src/sw.js b/src/sw.ts similarity index 63% rename from src/sw.js rename to src/sw.ts index 117f1e6..e56dbb0 100644 --- a/src/sw.js +++ b/src/sw.ts @@ -4,10 +4,16 @@ import { SWReplay } from "@webrecorder/wabac/src/swmain"; import { WorkerLoader } from "@webrecorder/wabac/src/loaders"; -if (self.registration) { +type Self = Window & + typeof globalThis & { + registration: { scope: string }; + sw: SWReplay; + }; + +if ((self as Self).registration) { const staticData = new Map(); - const prefix = self.registration.scope; + const prefix = (self as Self).registration.scope; staticData.set(prefix, { type: "text/html", content: INDEX_HTML }); staticData.set(prefix + "index.html", { @@ -17,13 +23,13 @@ if (self.registration) { const sp = new URLSearchParams(self.location.search); - const defaultConfig = {}; + const defaultConfig: { injectScripts?: string[] } = {}; if (sp.get("ruffle") == "1") { defaultConfig.injectScripts = ["ruffle/ruffle.js"]; } - self.sw = new SWReplay({ staticData, defaultConfig }); + (self as Self).sw = new SWReplay({ staticData, defaultConfig }); } else { new WorkerLoader(self); }