feat: settings defaults, storage layer, color scheme attribute
This commit is contained in:
@@ -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();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user