Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pkrasicki committed Jan 21, 2023
0 parents commit 7ee750c
Show file tree
Hide file tree
Showing 8 changed files with 796 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Mute Site
This is a Firefox extension that allows to instantly mute/unmute all tabs from a website. The mute button appears when a tab is playing audio. When pressed it will toggle mute on all tabs from that domain.

![screenshot](screenshots/screenshot.png)

![screenshot](screenshots/screenshot2.png)

Icons come from [Font Awesome](https://fontawesome.com) - CC BY 4.0 license.
60 changes: 60 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const MUTE_ICON = "icons/mute.svg";
const UNMUTE_ICON = "icons/unmute.svg";
const MUTE_TITLE = "Mute Site";
const UNMUTE_TITLE = "Unmute Site";

const toggleMuteSite = async () =>
{
try
{
const activeTabs = await browser.tabs.query({active: true, currentWindow: true});
const curTab = activeTabs[0];
const isCurTabMuted = curTab.mutedInfo.muted;
const domainName = new URL(curTab.url).hostname;

const tabs = await browser.tabs.query({
url: `*://*.${domainName}/*`
});

tabs.forEach((tab) =>
{
browser.tabs.update(tab.id, {
muted: !isCurTabMuted
});
});
} catch (error)
{
console.log(`Error: ${error}`);
}
};

const initializePageAction = (tab) =>
{
if (tab.audible) // if tab is playing media
{
const title = tab.mutedInfo.muted ? UNMUTE_TITLE : MUTE_TITLE;
const icon = tab.mutedInfo.muted ? UNMUTE_ICON : MUTE_ICON;

browser.pageAction.setTitle({tabId: tab.id, title: title});
browser.pageAction.setIcon({tabId: tab.id, path: icon});
browser.pageAction.show(tab.id);
}
}

// initialize for all tabs
browser.tabs.query({}).then((tabs) =>
{
for (let tab of tabs)
{
initializePageAction(tab);
}
});

// update page action on each tab update
browser.tabs.onUpdated.addListener((id, changeInfo, tab) =>
{
initializePageAction(tab);
});

// mute/unmute site when the page action is clicked
browser.pageAction.onClicked.addListener(toggleMuteSite);
15 changes: 15 additions & 0 deletions icons/mute.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions icons/unmute.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"manifest_version": 2,
"name": "Mute Site",
"version": "1.0",
"description": "Allows to instantly mute/unmute all tabs from a website.",

"icons": {
"48": "icons/unmute.svg",
"96": "icons/unmute.svg"
},

"permissions": [
"tabs"
],

"page_action": {
"default_icon": "icons/unmute.svg",
"default_title": "Toggle Mute Site"
},

"background": {
"scripts": ["background.js"]
}
}
Binary file added screenshots/screenshot.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 screenshots/screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7ee750c

Please sign in to comment.