Repository navigation
Expand file tree
/
Copy pathsettings.js.bak
More file actions
1 lines (1 loc) · 3.4 KB
/
Copy pathsettings.js.bak
File metadata and controls
1 lines (1 loc) · 3.4 KB
1
import"./chunks/modulepreload-polyfill-YP0FEG5d.js";class e{constructor(){this.init()}init(){this.loadSettings(),this.bindEvents(),this.applyTheme(),this.showWelcomeMessage()}bindEvents(){document.getElementById("savePreferences")?.addEventListener("click",()=>{this.savePreferences()});document.querySelectorAll("input, select").forEach(e=>{e.addEventListener("change",()=>{this.autoSavePreferences()})})}async loadSettings(){try{const e=await chrome.storage.sync.get(["autoImport","showNotifications","enableAdvancedMode","defaultFormat","Solaxnm_settings"]),t=e.Solaxnm_settings||e;document.getElementById("autoImport").checked=!1!==t.autoImport,document.getElementById("showNotifications").checked=!1!==t.showNotifications,document.getElementById("enableAdvancedMode").checked=!1!==t.enableAdvancedMode,document.getElementById("defaultFormat").value=t.defaultFormat||"png"}catch(e){console.error("Failed to load settings:",e),this.showToast("Failed to load settings","error")}}async savePreferences(){try{const e={autoImport:document.getElementById("autoImport").checked,showNotifications:document.getElementById("showNotifications").checked,enableAdvancedMode:document.getElementById("enableAdvancedMode").checked,defaultFormat:document.getElementById("defaultFormat").value};await chrome.storage.sync.set({...e,Solaxnm_settings:e});const t=document.getElementById("savePreferences"),o=t.innerHTML;t.innerHTML='\n <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <path d="m9 12 2 2 4-4"/>\n </svg>\n Saved!\n ',t.style.background="var(--success)",setTimeout(()=>{t.innerHTML=o,t.style.background=""},2e3),this.showToast("Preferences saved successfully!","success")}catch(e){console.error("Failed to save preferences:",e),this.showToast("Failed to save preferences","error")}}async autoSavePreferences(){clearTimeout(this.autoSaveTimeout),this.autoSaveTimeout=setTimeout(()=>{this.savePreferences()},1e3)}applyTheme(){window.matchMedia("(prefers-color-scheme: dark)").matches&&document.documentElement.setAttribute("data-theme","dark"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{document.documentElement.setAttribute("data-theme",e.matches?"dark":"light")})}showWelcomeMessage(){chrome.storage.local.get(["settingsVisited"]).then(e=>{e.settingsVisited||(setTimeout(()=>{this.showToast("Welcome to SolanaM Image Studio! All features are ready to use.","info")},1e3),chrome.storage.local.set({settingsVisited:!0}))})}showToast(e,t="info"){document.querySelectorAll(".toast").forEach(e=>e.remove());const o=document.createElement("div");o.className=`toast ${t}`,o.textContent=e,document.body.appendChild(o),setTimeout(()=>o.classList.add("show"),10),setTimeout(()=>{o.classList.remove("show"),setTimeout(()=>{document.body.contains(o)&&document.body.removeChild(o)},300)},4e3)}}document.addEventListener("DOMContentLoaded",()=>{new e}),"undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.id?console.log("SolanaM Image Studio Settings - Extension Context"):(console.warn("Settings page loaded outside extension context"),document.body.innerHTML='\n <div style="display: flex; align-items: center; justify-content: center; height: 100vh; text-align: center; font-family: system-ui;">\n <div>\n <h1>SolanaM Image Studio Settings</h1>\n <p>This page must be opened from the browser extension.</p>\n </div>\n </div>\n ');