feat: settings defaults, storage layer, color scheme attribute

This commit is contained in:
Joel Brock
2026-04-23 08:52:12 -07:00
parent 0c333a99f1
commit e1145c6f70
2 changed files with 151 additions and 3 deletions

View File

@@ -1,7 +1,45 @@
// Outlook Relook — Content Script Entry Point
// Loaded by manifest on outlook.office.com/*
(function () {
'use strict';
console.log('[Outlook Relook] Content script loaded');
const OR = window.OutlookRelook;
async function init() {
const settings = await OR.loadSettings();
console.log('[Outlook Relook] Loaded settings:', settings);
// Apply color scheme attribute
applyColorScheme(settings.colorScheme);
// Listen for setting changes from popup
chrome.storage.onChanged.addListener((changes, area) => {
if (area !== 'sync') return;
console.log('[Outlook Relook] Settings changed:', changes);
// Re-apply color scheme if it changed
if (changes.colorScheme) {
applyColorScheme(changes.colorScheme.newValue);
}
});
}
function applyColorScheme(scheme) {
let resolved = scheme;
if (scheme === 'system') {
resolved = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
document.documentElement.setAttribute('data-outlook-relook-scheme', resolved);
console.log('[Outlook Relook] Color scheme:', resolved);
}
// Listen for system theme changes when scheme is 'system'
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', async () => {
const settings = await OR.loadSettings();
if (settings.colorScheme === 'system') {
applyColorScheme('system');
}
});
init();
})();