winzik/skeleton-chrome/options/options.js

21 lines
867 B
JavaScript

// The options page (chrome://extensions > Details > Extension options, or the popup's link): saved with
// chrome.storage.sync, so they follow the user's Chrome profile. The content scripts hear the change themselves.
import { getSettings, saveSettings } from '../lib/settings.js';
import { t, translatePage } from '../lib/i18n.js';
translatePage();
const form = document.getElementById('form');
const status = document.getElementById('status');
const settings = await getSettings();
form.term.value = settings.term;
form.color.value = settings.color;
form.enabled.checked = settings.enabled;
form.addEventListener('submit', async (e) => {
e.preventDefault();
await saveSettings({ term: form.term.value, color: form.color.value, enabled: form.enabled.checked });
status.textContent = t('saved');
setTimeout(() => { status.textContent = ''; }, 2000);
});