Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fefranca committed Jun 25, 2021
0 parents commit d9c5eea
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2021 Fernando França

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Mute Google Meet
================

Chrome extension for muting/unmuting Google Meet from any tab.

80 changes: 80 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Iterate through Google Meet tabs, fetch status
async function updateStatus() {
var activeCount = 0;
var muted = false;
var activeTab = null
var tabs = await chrome.tabs.query({ url: "https://meet.google.com/*" });

// Use getTabStatus script for each Google Meet tab
const meetTabStatuses = tabs.map(async function (tab) {
let injectionResults = await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['getTabStatus.js'],
});
if (injectionResults[0].result[0]) {
activeCount++;
activeTab = tab;
muted = injectionResults[0].result[1];
}
});
await Promise.all(meetTabStatuses);

// Should display status only if a single Google Meet instance is active
if (activeCount == 1) {
badgeText = "";
badgeTitle = muted ? "unmute Google Meet" : "mute Google Meet";
badgeIcon = muted ? "icon128_muted.png" : "icon128_active.png";
activeTab = activeTab;
}
else {
badgeText = (activeCount >= 2) ? "Error" : "";
badgeTitle = (activeCount >= 2) ? "Multiple active Google Meet tabs" : "No active Google Meet tabs";
badgeIcon = "icon128.png";
}

chrome.action.setBadgeText({ text: badgeText });
chrome.action.setTitle({ title: badgeTitle })
chrome.action.setIcon({ path: "images/" + badgeIcon })

return (activeCount == 1) ? activeTab.id : null;
}

// Inject keypress for toggling mute in active Google Meet tab
async function sendKeypress(tab) {
var activeTabID = await updateStatus();
if (activeTabID != null) {
await chrome.scripting.executeScript(
{
target: { tabId: activeTabID },
files: ['dispatchKey.js'],
}
);
}
}

// Extension icon clicked
chrome.action.onClicked.addListener(async function (tab) {
await sendKeypress();
updateStatus();
});

// Runs after a tab has been loaded or its audible state changed
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status == "complete" || changeInfo.hasOwnProperty("audible")) {
updateStatus();
}
});

// Any tab has been removed
chrome.tabs.onRemoved.addListener(function (tabId, removeInfo) {
updateStatus();
});

// Prevent showing incorrect state on page suspend
chrome.runtime.onSuspend.addListener(function () {
chrome.action.setIcon({ path: "images/icon128.png" });
chrome.action.setBadgeText({ text: "" });
})

// Update status on load
updateStatus();
13 changes: 13 additions & 0 deletions dispatchKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Dispatch Cmd + D (metaKey) for Mac OS or Ctrl + D (ctrlKey) otherwise
var macOS = (navigator.userAgent.indexOf("Mac") != -1);

document.dispatchEvent(
new KeyboardEvent("keydown", {
metaKey: macOS,
ctrlKey: !macOS,
bubbles: true,
cancelable: true,
keyCode: 68,
code: "KeyD"
})
);
17 changes: 17 additions & 0 deletions getTabStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Verify if this meeting is active and the status of the mute button
var active = false;
var muted = false;

var buttons = document.getElementsByTagName("button");
for (var elem of buttons) {
if (elem.hasAttribute("data-is-muted")) {
active = true;
if (elem.getAttribute("data-is-muted") === "true") {
muted = true;
}
// Note: video button also has data-is-muted attribute
break;
}
}

[active, muted]
Binary file added images/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon128_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon128_muted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"manifest_version": 3,
"name": "Mute Google Meet",
"description": "Mutes Google Meet from any tab.",
"version": "1.0",
"author": "Fernando França",
"icons": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_title": "Mute Google Meet"
},
"permissions": [
"scripting",
"tabs"
],
"host_permissions": [
"https://meet.google.com/"
]
}

0 comments on commit d9c5eea

Please sign in to comment.