From 46f785a12ccd402d18f178a8711e99e3a871a567 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 24 Sep 2016 09:41:23 +0100 Subject: Add "all" and "other" options for toggleMuteTab. This adds advanced options for toggleMuteTab. Examples: map X toggleMuteTab all map Y toggleMuteTab other In the first case, all audible, unmuted tabs are muted; otherwise all muted tabs are unmuted. The second case is the same, except that the current tab is excluded from consideration. Follow on from #2269. --- background_scripts/main.coffee | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index d9b527ef..b99b975f 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -155,6 +155,23 @@ TabOperations = openerTabId: request.tab.id chrome.tabs.create tabConfig, callback +toggleMuteTab = do -> + muteTab = (tab) -> chrome.tabs.update tab.id, {muted: !tab.mutedInfo.muted} + + ({tab: currentTab, registryEntry}) -> + if registryEntry.options.all? or registryEntry.options.other? + # If there are any audible, unmuted tabs, then we mute them; otherwise we unmute any muted tabs. + chrome.tabs.query {audible: true}, (tabs) -> + if registryEntry.options.other? + tabs = (tab for tab in tabs when tab.id != currentTab.id) + audibleUnmutedTabs = (tab for tab in tabs when tab.audible and not tab.mutedInfo.muted) + if 0 < audibleUnmutedTabs.length + muteTab tab for tab in audibleUnmutedTabs + else + muteTab tab for tab in tabs when tab.mutedInfo.muted + else + muteTab currentTab + # # Selects the tab with the ID specified in request.id # @@ -210,7 +227,7 @@ BackgroundCommands = openCopiedUrlInCurrentTab: (request) -> TabOperations.openUrlInCurrentTab extend request, url: Clipboard.paste() openCopiedUrlInNewTab: (request) -> @createTab extend request, url: Clipboard.paste() togglePinTab: ({tab}) -> chrome.tabs.update tab.id, {pinned: !tab.pinned} - toggleMuteTab: ({tab}) -> chrome.tabs.update tab.id, {muted: !tab.mutedInfo.muted} + toggleMuteTab: toggleMuteTab moveTabLeft: moveTab moveTabRight: moveTab nextFrame: ({count, frameId, tabId}) -> -- cgit v1.2.3