Skip to content

Commit

Permalink
Change browser icon depending on active/inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
stijn-uva committed Feb 20, 2024
1 parent 46e048f commit 6d97ec5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Binary file added images/zeeschuimer-icon-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/zeeschuimer-icon-inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions js/zs-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ window.zeeschuimer = {
this.session = session["value"];
await db.settings.update("session", session);
await db.nav.where("session").notEqual(this.session).delete();

// synchronise browser icon with whether capture is enabled or not
setInterval(async function () {
let enabled = [];
for (const module in zeeschuimer.modules) {
const enabled_key = 'zs-enabled-' + module;
const is_enabled = await browser.storage.local.get(enabled_key);
if (is_enabled.hasOwnProperty(enabled_key) && !!parseInt(is_enabled[enabled_key])) {
enabled.push(module);
}
}
let path = enabled.length > 0 ? 'images/zeeschuimer-icon-active.png' : 'images/zeeschuimer-icon-inactive.png';
browser.browserAction.setIcon({path: path})
}, 500);
},

/**
Expand Down
11 changes: 11 additions & 0 deletions popup/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ async function toggle_listening(e) {
await background.browser.storage.local.set({[platform]: String(updated)});
}


/**
* Update favicon depending on whether capture is enabled
*/
function update_icon() {
const any_enabled = Array.from(document.querySelectorAll('.toggle-switch input')).filter(item => item.checked);
const path = any_enabled.length > 0 ? '/images/zeeschuimer-icon-active.png' : '/images/zeeschuimer-icon-inactive.png';
document.querySelector('link[rel~=icon]').setAttribute('href', path);
}

/**
* Get Zeeschuimer stats
*
Expand Down Expand Up @@ -249,6 +259,7 @@ async function get_stats() {

set_4cat_url(true);
activate_buttons();
update_icon();
init_tooltips();
}

Expand Down

0 comments on commit 6d97ec5

Please sign in to comment.