Add color update on install to background.js, tweak recent changes

This commit is contained in:
Jean Viscogliosi-Pate 2025-06-29 14:10:49 -07:00
parent 5dafbbc59c
commit fdcce37656
3 changed files with 7 additions and 2 deletions

View File

@ -13,7 +13,7 @@
"scripts": {
"test": "cp src/manifest-firefox.json src/manifest.json && npx rollup -c && npx web-ext run -s src && rm src/manifest.json",
"test-chrome": "cp src/manifest-chrome.json src/manifest.json && npx rollup -c && chromium && rm src/manifest.json",
"build": "cp src/manifest-firefox.json src/manifest.json && npx rollup -c && npx web-ext build -s src -a dist --ignore-files replace-words.js save-load-options.js manifest-* service-worker* -n {name}-{version}-firefox.zip -o && rm src/manifest.json",
"build": "cp src/manifest-firefox.json src/manifest.json && npx rollup -c && npx web-ext build -s src -a dist --ignore-files replace-words.js save-load-options.js manifest-* service-worker* -n {name}-{version}.xpi -o && rm src/manifest.json",
"build-chrome": "cp src/manifest-chrome.json src/manifest.json && npx rollup -c && npx web-ext build -s src -a dist --ignore-files replace-words.js save-load-options.js manifest-* background.js -n {name}-{version}-chrome.zip -o && rm src/manifest.json"
},
"devDependencies": {

View File

@ -16,6 +16,7 @@ function updateIcon(event) {
}
/* Listen for color scheme changes */
browser.runtime.onInstalled.addListener(updateColorSchemeOnInstall);
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', updateColorScheme);
/* Update the color scheme to light or dark */
@ -30,6 +31,11 @@ function updateColorScheme(event) {
updateIcon();
}
/* Updatw the color scheme on install */
function updateColorSchemeOnInstall() {
updateColorScheme(window.matchMedia('(prefers-color-scheme: dark)'));
}
/* Listen for tab changes */
window.addEventListener("load", updateState());
browser.tabs.onUpdated.addListener(updateStateOnReload, {urls: ["*://*/*"]});

View File

@ -2,7 +2,6 @@
updateColorScheme(window.matchMedia('(prefers-color-scheme: dark)'));
function updateColorScheme(event) {
console.log("doing!");
chrome.runtime.sendMessage({
content: "colorScheme",
isDark: event.matches