summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFranklinDM <mrmineshafter17@gmail.com>2018-11-16 22:58:46 +0800
committerFranklinDM <mrmineshafter17@gmail.com>2018-11-16 22:58:46 +0800
commiteff89e1c9d7ccfbfb09fb615848b7e288e8b2c7d (patch)
tree11fd80a72adbb48fa70299742116df62750cf57e
parent719234847ecbab2fe8b4b4c2f153fa0c12bffbc6 (diff)
downloadUXP-eff89e1c9d7ccfbfb09fb615848b7e288e8b2c7d.tar
UXP-eff89e1c9d7ccfbfb09fb615848b7e288e8b2c7d.tar.gz
UXP-eff89e1c9d7ccfbfb09fb615848b7e288e8b2c7d.tar.lz
UXP-eff89e1c9d7ccfbfb09fb615848b7e288e8b2c7d.tar.xz
UXP-eff89e1c9d7ccfbfb09fb615848b7e288e8b2c7d.zip
Issue #638 - Part 5: Add mute/unmute option to tab context menu
-rw-r--r--application/palemoon/base/content/browser.js40
-rw-r--r--application/palemoon/base/content/browser.xul1
-rw-r--r--application/palemoon/locales/en-US/chrome/browser/browser.properties5
3 files changed, 46 insertions, 0 deletions
diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js
index 4167f186c..5d44f0066 100644
--- a/application/palemoon/base/content/browser.js
+++ b/application/palemoon/base/content/browser.js
@@ -7021,6 +7021,17 @@ function restoreLastSession() {
var TabContextMenu = {
contextTab: null,
+ _updateToggleMuteMenuItem(aTab, aConditionFn) {
+ ["muted", "soundplaying"].forEach(attr => {
+ if (!aConditionFn || aConditionFn(attr)) {
+ if (aTab.hasAttribute(attr)) {
+ aTab.toggleMuteMenuItem.setAttribute(attr, "true");
+ } else {
+ aTab.toggleMuteMenuItem.removeAttribute(attr);
+ }
+ }
+ });
+ },
updateContextMenu: function updateContextMenu(aPopupMenu) {
this.contextTab = aPopupMenu.triggerNode.localName == "tab" ?
aPopupMenu.triggerNode : gBrowser.selectedTab;
@@ -7067,6 +7078,35 @@ var TabContextMenu = {
bookmarkAllTabs.hidden = this.contextTab.pinned;
if (!bookmarkAllTabs.hidden)
PlacesCommandHook.updateBookmarkAllTabsCommand();
+
+ // Adjust the state of the toggle mute menu item.
+ let toggleMute = document.getElementById("context_toggleMuteTab");
+ if (this.contextTab.hasAttribute("muted")) {
+ toggleMute.label = gNavigatorBundle.getString("unmuteTab.label");
+ toggleMute.accessKey = gNavigatorBundle.getString("unmuteTab.accesskey");
+ } else {
+ toggleMute.label = gNavigatorBundle.getString("muteTab.label");
+ toggleMute.accessKey = gNavigatorBundle.getString("muteTab.accesskey");
+ }
+
+ this.contextTab.toggleMuteMenuItem = toggleMute;
+ this._updateToggleMuteMenuItem(this.contextTab);
+
+ this.contextTab.addEventListener("TabAttrModified", this, false);
+ aPopupMenu.addEventListener("popuphiding", this, false);
+ },
+ handleEvent(aEvent) {
+ switch (aEvent.type) {
+ case "popuphiding":
+ gBrowser.removeEventListener("TabAttrModified", this);
+ aEvent.target.removeEventListener("popuphiding", this);
+ break;
+ case "TabAttrModified":
+ let tab = aEvent.target;
+ this._updateToggleMuteMenuItem(tab,
+ attr => aEvent.detail.changed.indexOf(attr) >= 0);
+ break;
+ }
}
};
diff --git a/application/palemoon/base/content/browser.xul b/application/palemoon/base/content/browser.xul
index 07ca54722..ce2a7c5a8 100644
--- a/application/palemoon/base/content/browser.xul
+++ b/application/palemoon/base/content/browser.xul
@@ -87,6 +87,7 @@
onpopuphidden="if (event.target == this) TabContextMenu.contextTab = null;">
<menuitem id="context_reloadTab" label="&reloadTab.label;" accesskey="&reloadTab.accesskey;"
oncommand="gBrowser.reloadTab(TabContextMenu.contextTab);"/>
+ <menuitem id="context_toggleMuteTab" oncommand="TabContextMenu.contextTab.toggleMuteAudio();"/>
<menuseparator/>
<menuitem id="context_pinTab" label="&pinTab.label;"
accesskey="&pinTab.accesskey;"
diff --git a/application/palemoon/locales/en-US/chrome/browser/browser.properties b/application/palemoon/locales/en-US/chrome/browser/browser.properties
index 9969bd753..dbe6dbaa1 100644
--- a/application/palemoon/locales/en-US/chrome/browser/browser.properties
+++ b/application/palemoon/locales/en-US/chrome/browser/browser.properties
@@ -397,3 +397,8 @@ slowStartup.helpButton.label = Learn How to Speed It Up
slowStartup.helpButton.accesskey = L
slowStartup.disableNotificationButton.label = Don't Tell Me Again
slowStartup.disableNotificationButton.accesskey = A
+
+muteTab.label = Mute Tab
+muteTab.accesskey = M
+unmuteTab.label = Unmute Tab
+unmuteTab.accesskey = M \ No newline at end of file