From 6207d8a75e40aa76008edaffbbe138bbc9f6baa4 Mon Sep 17 00:00:00 2001 From: auric <104602845+ihateamongus@users.noreply.github.com> Date: Thu, 11 Sep 2025 15:13:57 -0500 Subject: Add dynamic Firefox accent color extension --- browsers/firefox/extension/background.js | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 browsers/firefox/extension/background.js (limited to 'browsers/firefox/extension/background.js') diff --git a/browsers/firefox/extension/background.js b/browsers/firefox/extension/background.js new file mode 100644 index 0000000..df0ee80 --- /dev/null +++ b/browsers/firefox/extension/background.js @@ -0,0 +1,34 @@ +let port = browser.runtime.connectNative("accent_color"); +let current = null; + +function broadcast(color) { + browser.tabs.query({}).then(tabs => { + for (let tab of tabs) { + browser.tabs.sendMessage(tab.id, {color}).catch(() => {}); + } + }); + browser.theme.update({colors: {toolbar: color}}); +} + +port.onMessage.addListener(msg => { + if (msg.color && msg.color !== current) { + current = msg.color; + broadcast(current); + } +}); + +function poll() { + try { + port.postMessage({query: "color"}); + } catch (e) { + // ignore + } +} +setInterval(poll, 1000); +poll(); + +browser.runtime.onMessage.addListener((msg, sender) => { + if (msg.request === "color") { + return Promise.resolve({color: current}); + } +}); -- cgit v1.2.3