diff --git a/global/theme.js b/global/theme.js index bce6964..2f5c6b9 100644 --- a/global/theme.js +++ b/global/theme.js @@ -3,7 +3,6 @@ try { document.documentElement.setAttribute("data-theme", theme); await storageManager.set("themePreference", theme); - localStorage.setItem("themePreference", theme); chrome.runtime .sendMessage({ action: "themeChanged", @@ -103,22 +102,11 @@ async function initializeTheme() { try { - const storageTheme = await storageManager.get("themePreference"); - const localStorageTheme = localStorage.getItem("themePreference"); - - const theme = storageTheme || localStorageTheme || "light-green"; + const theme = await storageManager.get("themePreference", "light-green"); await setTheme(theme); setPageTitleAndFavicon(); importFonts(); - - if (storageTheme !== localStorageTheme) { - if (storageTheme) { - localStorage.setItem("themePreference", storageTheme); - } else if (localStorageTheme) { - await storageManager.set("themePreference", localStorageTheme); - } - } } catch (error) { console.error("Error initializing theme:", error); await setTheme("light-green"); @@ -154,8 +142,7 @@ const currentTheme = document.documentElement.getAttribute("data-theme"); try { - const savedTheme = await storageManager.get("themePreference") || - localStorage.getItem("themePreference"); + const savedTheme = await storageManager.get("themePreference"); if ( (!currentTheme && savedTheme) || diff --git a/login/twofactor.js b/login/twofactor.js index bb98ae5..b925b07 100644 --- a/login/twofactor.js +++ b/login/twofactor.js @@ -104,10 +104,8 @@ async function transformTwoFactorPage() { function applyTheme() { try { - if (typeof getCookie === "function") { - const theme = getCookie("theme") || "light-green"; - document.documentElement.setAttribute("data-theme", theme); - } + const theme = localStorage.getItem("themePreference") || "light-green"; + document.documentElement.setAttribute("data-theme", theme); } catch (error) { } } diff --git a/settings/index.html b/settings/index.html index f5d4996..e958160 100644 --- a/settings/index.html +++ b/settings/index.html @@ -226,11 +226,10 @@ - diff --git a/settings/index.js b/settings/index.js index 8d681a0..4c5d267 100644 --- a/settings/index.js +++ b/settings/index.js @@ -3,38 +3,9 @@ document.addEventListener("DOMContentLoaded", async () => { await new Promise((resolve) => setTimeout(resolve, 10)); } - - - - - function getCookie(name) { - const cookieName = `${name}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const cookieArray = decodedCookie.split(";"); - - for (let i = 0; i < cookieArray.length; i++) { - let cookie = cookieArray[i]; - while (cookie.charAt(0) === " ") { - cookie = cookie.substring(1); - } - if (cookie.indexOf(cookieName) === 0) { - return cookie.substring(cookieName.length, cookie.length); - } - } - return null; - } - - function setCookie(name, value, days = 365) { - const date = new Date(); - date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); - const expires = `expires=${date.toUTCString()}`; - document.cookie = `${name}=${value}; ${expires}; path=/; domain=.e-kreta.hu`; - } - function getCurrentTheme() { return ( localStorage.getItem("themePreference") || - getCookie("themePreference") || "light-green" ); } @@ -50,7 +21,6 @@ document.addEventListener("DOMContentLoaded", async () => { function getCurrentLanguage() { return ( localStorage.getItem("languagePreference") || - getCookie("languagePreference") || "hu" ); } @@ -63,7 +33,6 @@ document.addEventListener("DOMContentLoaded", async () => { } async function applyLanguage(language) { - setCookie("languagePreference", language); localStorage.setItem("languagePreference", language); updateLanguageButtons(language); @@ -80,7 +49,6 @@ document.addEventListener("DOMContentLoaded", async () => { } async function applyTheme(theme) { - setCookie("themePreference", theme); localStorage.setItem("themePreference", theme); document.documentElement.setAttribute("data-theme", theme); @@ -142,8 +110,6 @@ document.addEventListener("DOMContentLoaded", async () => { const versionElement = document.getElementById("version"); versionElement.textContent = `v${manifest.version}`; - - themeButtons.forEach((button) => { button.addEventListener("mouseover", () => { if (!button.hasAttribute("disabled")) { @@ -233,12 +199,10 @@ document.addEventListener("DOMContentLoaded", async () => { const theme = this.customThemes.find(t => t.id === themeId); if (theme) { this.applyCustomThemeColors(theme.colors); - setCookie("themePreference", themeId); localStorage.setItem("themePreference", themeId); } } else { document.documentElement.setAttribute('data-theme', themeId); - setCookie("themePreference", themeId); localStorage.setItem("themePreference", themeId); } updateThemeButtons(themeId); diff --git a/tools/storageManager.js b/tools/storageManager.js index b5d9a27..fd04c1e 100644 --- a/tools/storageManager.js +++ b/tools/storageManager.js @@ -33,10 +33,8 @@ const storageManager = { localStorage.setItem(prefixedKey, JSON.stringify(value)); } } catch (error) { - console.warn(`[StorageManager] Primary storage failed for ${key}, falling back to cookie:`, error); - if (typeof cookieManager !== 'undefined') { - cookieManager.set(prefixedKey, JSON.stringify(value)); - } + console.warn(`[StorageManager] Storage failed for ${key}:`, error); + throw error; } }, @@ -72,17 +70,7 @@ const storageManager = { return defaultValue; } } catch (error) { - console.warn(`[StorageManager] Primary storage failed for ${key}, falling back to cookie:`, error); - if (typeof cookieManager !== 'undefined') { - const cookieValue = cookieManager.get(prefixedKey); - if (cookieValue) { - try { - return JSON.parse(cookieValue); - } catch (parseError) { - return cookieValue; - } - } - } + console.warn(`[StorageManager] Storage failed for ${key}:`, error); return defaultValue; } }, @@ -153,41 +141,4 @@ const storageManager = { } }, - async migrateFromCookies() { - if (typeof cookieManager === 'undefined') { - return; - } - - const knownSettings = [ - 'theme', 'language', 'notifications', 'autoRefresh', - 'compactMode', 'showGrades', 'showAbsences' - ]; - - let migratedCount = 0; - - for (const setting of knownSettings) { - try { - const cookieValue = cookieManager.get(`firka_${setting}`); - if (cookieValue !== null) { - let value; - try { - value = JSON.parse(cookieValue); - } catch { - value = cookieValue; - } - - await this.set(setting, value); - migratedCount++; - } - } catch (error) { - console.warn(`[StorageManager] Failed to migrate ${setting}:`, error); - } - } - } -}; - -if (typeof document !== 'undefined') { - document.addEventListener('DOMContentLoaded', () => { - storageManager.migrateFromCookies().catch(console.error); - }); -} \ No newline at end of file +}; \ No newline at end of file