function injectCSS(css) { const styleId = "dynamic-css-injector-style"; let style = document.getElementById(styleId); if (!style) { style = document.createElement("style"); style.id = styleId; document.documentElement.appendChild(style); } style.textContent = css; } function applySiteCSS() { const domain = location.hostname; chrome.storage.sync.get([domain], (result) => { const css = result[domain]; if (css) injectCSS(css); }); } // Run when content script loads applySiteCSS(); // Listen for background requests to reapply chrome.runtime.onMessage.addListener((msg) => { if (msg.type === "applyCSS") applySiteCSS(); });