-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7ee750c
Showing
8 changed files
with
796 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.