-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeet_controller.js
59 lines (55 loc) · 1.43 KB
/
meet_controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
var icon = chrome.runtime.getURL('mute.svg'); // default icon for notification
var message = 'Could not locate Mute control in Google Meeting.'; // default notification message
// find mute or unmute button on this Meeting page. only one of these will exist at a time
const muteButton = document.querySelector("[aria-label*='Turn off microphone']");
const unmuteButton = document.querySelector("[aria-label*='Turn on microphone']");
// function for muting
const mute = () => {
const btn = muteButton;
if (btn !== null) {
btn.click();
message = 'Microphone is OFF';
icon = chrome.runtime.getURL('mute.svg');
sendResponse({
notification: {
type: 'basic',
iconUrl: icon,
title: message,
message: ''
}
});
} else {
//send empty response
sendResponse({});
}
};
const unmute = () => {
const btn = unmuteButton;
if (btn !== null) {
btn.click();
message = 'Microphone is ON';
icon = chrome.runtime.getURL('unmute.svg');
sendResponse({
notification: {
type: 'basic',
iconUrl: icon,
title: message,
message: ''
}
});
} else {
//send empty response
sendResponse({});
}
};
if (request.command === 'toggle') {
if (muteButton !== null) {
// if the mute button exists, then the Mic is currently unmuted.
mute();
} else {
// ... and vice-versa.
unmute();
}
}
});