MCPcopy
hub / github.com/philc/vimium / toggleMuteTab

Function toggleMuteTab

background_scripts/main.js:106–157  ·  view source on GitHub ↗
(request, sender)

Source from the content-addressed store, hash-verified

104}
105
106function toggleMuteTab(request, sender) {
107 const currentTab = request.tab;
108 const tabId = request.tabId;
109 const registryEntry = request.registryEntry;
110
111 if ((registryEntry.options.all != null) || (registryEntry.options.other != null)) {
112 // If there are any audible, unmuted tabs, then we mute them; otherwise we unmute any muted tabs.
113 chrome.tabs.query({ audible: true }, function (tabs) {
114 let tab;
115 if (registryEntry.options.other != null) {
116 tabs = tabs.filter((t) => t.id !== currentTab.id);
117 }
118 const audibleUnmutedTabs = tabs.filter((t) => t.audible && !t.mutedInfo.muted);
119 if (audibleUnmutedTabs.length >= 0) {
120 chrome.tabs.sendMessage(tabId, {
121 frameId: sender.frameId,
122 handler: "showMessage",
123 message: `Muting ${audibleUnmutedTabs.length} tab(s).`,
124 });
125 for (tab of audibleUnmutedTabs) {
126 muteTab(tab);
127 }
128 } else {
129 chrome.tabs.sendMessage(tabId, {
130 frameId: sender.frameId,
131 handler: "showMessage",
132 message: "Unmuting all muted tabs.",
133 });
134 for (tab of tabs) {
135 if (tab.mutedInfo.muted) {
136 muteTab(tab);
137 }
138 }
139 }
140 });
141 } else {
142 if (currentTab.mutedInfo.muted) {
143 chrome.tabs.sendMessage(tabId, {
144 frameId: sender.frameId,
145 handler: "showMessage",
146 message: "Unmuted tab.",
147 });
148 } else {
149 chrome.tabs.sendMessage(tabId, {
150 frameId: sender.frameId,
151 handler: "showMessage",
152 message: "Muted tab.",
153 });
154 }
155 muteTab(currentTab);
156 }
157}
158
159// Find a tab's actual index in a given tab array returned by chrome.tabs.query. In Firefox, there
160// may be hidden tabs, so tab.tabIndex may not be the actual index into the array of visible tabs.

Callers

nothing calls this directly

Calls 2

muteTabFunction · 0.85
filterMethod · 0.45

Tested by

no test coverage detected