diff options
| author | Stephen Blott | 2016-09-24 09:41:23 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-09-24 10:22:41 +0100 | 
| commit | 46f785a12ccd402d18f178a8711e99e3a871a567 (patch) | |
| tree | 527b0879f66689611a82a91f101eb99895294243 /background_scripts/main.coffee | |
| parent | 921429924c6b212f7d2a5d7cd15975f243cb2ed6 (diff) | |
| download | vimium-46f785a12ccd402d18f178a8711e99e3a871a567.tar.bz2 | |
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.
Diffstat (limited to 'background_scripts/main.coffee')
| -rw-r--r-- | background_scripts/main.coffee | 19 | 
1 files changed, 18 insertions, 1 deletions
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}) ->  | 
