From a3c2e7fd7a7c8d22b9defc5c09caed40ccedafb9 Mon Sep 17 00:00:00 2001 From: sameerasw Date: Tue, 6 May 2025 18:32:32 +0530 Subject: Implemented custom styles repository feature --- background.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'background.js') diff --git a/background.js b/background.js index 60fd68e..19ef0fe 100644 --- a/background.js +++ b/background.js @@ -818,11 +818,20 @@ function stopAutoUpdate() { async function refetchCSS() { if (logging) console.log("refetchCSS called"); try { - const response = await fetch( - "https://sameerasw.github.io/my-internet/styles.json", - { headers: { "Cache-Control": "no-cache" } } - ); - if (!response.ok) throw new Error("Failed to fetch styles.json"); + // Get the repository URL from storage or use the default one + const DEFAULT_REPOSITORY_URL = + "https://sameerasw.github.io/my-internet/styles.json"; + const repoUrlData = await browser.storage.local.get("stylesRepositoryUrl"); + const repositoryUrl = + repoUrlData.stylesRepositoryUrl || DEFAULT_REPOSITORY_URL; + + console.log("Background: Fetching styles from:", repositoryUrl); + + const response = await fetch(repositoryUrl, { + headers: { "Cache-Control": "no-cache" }, + }); + if (!response.ok) + throw new Error(`Failed to fetch styles (Status: ${response.status})`); const styles = await response.json(); await browser.storage.local.set({ styles }); @@ -849,7 +858,7 @@ async function refetchCSS() { await browser.storage.local.set({ lastFetchedTime: Date.now() }); } - console.info("All styles refetched and updated from GitHub."); + console.info(`All styles refetched and updated from ${repositoryUrl}`); // Preload the new styles preloadStyles(); -- cgit v1.2.3