Files
Outcut/content/content.js

46 lines
1.3 KiB
JavaScript

// Outlook Relook — Content Script Entry Point
(function () {
'use strict';
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();
})();