Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kenhendricks00 authored Nov 3, 2024
1 parent ead81a3 commit 8609081
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions platform/firefox/pub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ document.addEventListener("DOMContentLoaded", async () => {
return `${urlObj.protocol}//${urlObj.hostname}`;
}

// Function to apply theme based on settings
async function applyTheme() {
try {
const { theme } = await browser.storage.sync.get("theme");

if (theme === "dark") {
document.body.setAttribute("data-theme", "dark");
} else if (theme === "light") {
document.body.setAttribute("data-theme", "light");
} else {
const prefersDark = window.matchMedia(
"(prefers-color-scheme: dark)"
).matches;
document.body.setAttribute(
"data-theme",
prefersDark ? "dark" : "light"
);
}
} catch (error) {
console.error("Error applying theme:", error);
}
}

// Apply theme on load
await applyTheme();

try {
// Get the active tab's URL
const [activeTab] = await browser.tabs.query({
Expand Down Expand Up @@ -88,6 +114,12 @@ document.addEventListener("DOMContentLoaded", async () => {
`${displayUrl} is <strong>potentially unsafe</strong>. Proceed with caution.`
);
break;
case "fmhy":
updateUI(
"fmhy",
`${displayUrl} is an <strong>FMHY</strong> related site. Proceed confidently.`
);
break;
case "safe":
updateUI("safe", `${displayUrl} is <strong>safe</strong> to browse.`);
break;
Expand Down Expand Up @@ -120,6 +152,7 @@ document.addEventListener("DOMContentLoaded", async () => {
const icons = {
unsafe: "../res/icons/unsafe.png",
potentially_unsafe: "../res/icons/potentially_unsafe.png",
fmhy: "../res/icons/fmhy.png",
safe: "../res/icons/safe.png",
starred: "../res/icons/starred.png",
no_data: "../res/ext_icon_144.png",
Expand All @@ -137,4 +170,10 @@ document.addEventListener("DOMContentLoaded", async () => {

console.log(`UI updated: ${message}`);
}

// Add settings button functionality
document.getElementById("settingsButton").addEventListener("click", () => {
// Open the settings page in a new tab
browser.runtime.openOptionsPage();
});
});

0 comments on commit 8609081

Please sign in to comment.