From cd42fd3f920b2a3e9b67a5466a3b59c94cd2ab84 Mon Sep 17 00:00:00 2001 From: ririxi Date: Fri, 8 Dec 2023 00:50:45 +0100 Subject: [PATCH 1/2] feat: add support for ESM extensions --- src/extensions/extension.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/extensions/extension.tsx b/src/extensions/extension.tsx index b15eacae..763d94bf 100644 --- a/src/extensions/extension.tsx +++ b/src/extensions/extension.tsx @@ -67,6 +67,7 @@ import { const { user, repo, branch, filePath } = getParamsFromGithubRaw(extensionManifest.extensionURL); if (!user || !repo || !branch || !filePath) return; script.src = `https://cdn.jsdelivr.${tld}/gh/${user}/${repo}@${branch}/${filePath}`; + if (filePath.endsWith(".mjs")) script.type = "module"; } script.src = `${script.src}?time=${Date.now()}`; @@ -93,6 +94,7 @@ import { injectColourScheme(activeScheme); // Add to Spicetify.Config + // @ts-expect-error: `current_theme` is read-only type in types Spicetify.Config.color_scheme = themeManifest.activeScheme; if (localStorage.getItem(LOCALSTORAGE_KEYS.albumArtBasedColor) === "true") { initAlbumArtBasedColor(activeScheme); @@ -117,6 +119,7 @@ import { injectUserCSS(userCSS); // Add to Spicetify.Config + // @ts-expect-error: `current_theme` is read-only type in types Spicetify.Config.current_theme = themeManifest.manifest?.name; // Inject any included js @@ -130,7 +133,9 @@ import { // If it's a github raw script, use jsdelivr if (isGithubRawUrl(script)) { const { user, repo, branch, filePath } = getParamsFromGithubRaw(script); + if (!user || !repo || !branch || !filePath) return; src = `https://cdn.jsdelivr.${tld}/gh/${user}/${repo}@${branch}/${filePath}`; + if (filePath.endsWith(".mjs")) newScript.type = "module"; } // console.log({src}); newScript.src = `${src}?time=${Date.now()}`; @@ -164,7 +169,9 @@ import { window.sessionStorage.setItem("marketplace-request-tld", tld); // Save to Spicetify.Config for use when removing a theme + // @ts-expect-error: Config doesn't have a `local_theme` property Spicetify.Config.local_theme = Spicetify.Config.current_theme; + // @ts-expect-error: Config doesn't have a `local_color_scheme` property Spicetify.Config.local_color_scheme = Spicetify.Config.color_scheme; const installedThemeKey = localStorage.getItem(LOCALSTORAGE_KEYS.themeInstalled); if (installedThemeKey) initializeTheme(installedThemeKey); From 960846c80cfe1b82142ac10be4ea746421399937 Mon Sep 17 00:00:00 2001 From: ririxi Date: Fri, 8 Dec 2023 00:52:06 +0100 Subject: [PATCH 2/2] chore: put proper prop into expect-error --- src/extensions/extension.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/extension.tsx b/src/extensions/extension.tsx index 763d94bf..c618bfc3 100644 --- a/src/extensions/extension.tsx +++ b/src/extensions/extension.tsx @@ -94,7 +94,7 @@ import { injectColourScheme(activeScheme); // Add to Spicetify.Config - // @ts-expect-error: `current_theme` is read-only type in types + // @ts-expect-error: `color_scheme` is read-only type in types Spicetify.Config.color_scheme = themeManifest.activeScheme; if (localStorage.getItem(LOCALSTORAGE_KEYS.albumArtBasedColor) === "true") { initAlbumArtBasedColor(activeScheme);