Files
Phoenix/toggle-ext/bg.js
T
2026-06-02 20:56:19 +02:00

17 lines
636 B
JavaScript

// Aktiviert den bestehenden Tab mit Ziel-URL (ohne Reload). Falls nicht offen, wird er geöffnet.
function activateOrCreate(url) {
chrome.tabs.query({}, tabs => {
const t = tabs.find(tt => tt.url && tt.url.startsWith(url));
if (t) { chrome.tabs.update(t.id, {active: true}); }
else { chrome.tabs.create({url}); }
});
}
chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
if (msg && msg.cmd === 'toggle') {
if (msg.from === 'volumio') activateOrCreate('http://localhost:8088/');
else activateOrCreate('http://localhost:3000/');
sendResponse({ok:true});
}
});