summaryrefslogtreecommitdiff
path: root/popup/popup.js
diff options
context:
space:
mode:
authorSameera Sandakelum <[email protected]>2025-05-06 18:34:24 +0530
committerGitHub <[email protected]>2025-05-06 18:34:24 +0530
commit349c94e497a4b54bd5c1ebc7c6b1f9e6ac6cadf6 (patch)
tree3d294ea8d7b9fa7a2617d9ab5958eba80b8deb07 /popup/popup.js
parentf3f4079aabc93d2c92d943b95d0f2360ed6b1b79 (diff)
parenta3c2e7fd7a7c8d22b9defc5c09caed40ccedafb9 (diff)
Merge pull request #16 from sameerasw/custom-styles #14
Implemented custom styles repository feature #14
Diffstat (limited to 'popup/popup.js')
-rw-r--r--popup/popup.js28
1 files changed, 19 insertions, 9 deletions
diff --git a/popup/popup.js b/popup/popup.js
index 5f8071d..6844415 100644
--- a/popup/popup.js
+++ b/popup/popup.js
@@ -666,15 +666,24 @@ new (class ExtensionPopup {
if (logging) console.log("refetchCSS called");
this.refetchCSSButton.textContent = "Fetching...";
try {
- const response = await fetch(
- "https://sameerasw.github.io/my-internet/styles.json",
- {
- headers: {
- "Cache-Control": "no-cache",
- },
- }
+ // 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"
);
- if (!response.ok) throw new Error("Failed to fetch styles.json");
+ const repositoryUrl =
+ repoUrlData.stylesRepositoryUrl || DEFAULT_REPOSITORY_URL;
+
+ console.log("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 });
@@ -723,7 +732,7 @@ new (class ExtensionPopup {
setTimeout(() => {
this.refetchCSSButton.textContent = "Refetch latest styles";
}, 2000);
- console.info("All styles refetched and updated from GitHub." + styles);
+ console.info(`All styles refetched and updated from ${repositoryUrl}`);
this.displayLastFetchedTime();
} catch (error) {
this.refetchCSSButton.textContent = "Error!";
@@ -731,6 +740,7 @@ new (class ExtensionPopup {
this.refetchCSSButton.textContent = "Refetch latest styles";
}, 2000);
console.error("Error refetching styles:", error);
+ alert(`Error fetching styles: ${error.message}`);
}
}