-
Notifications
You must be signed in to change notification settings - Fork 3
/
togglemic.js
50 lines (48 loc) · 1.97 KB
/
togglemic.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
let micButton;
function handleMicClick(event) {
let micMuted;
setTimeout(function () {
if(document.querySelectorAll('.GKGgdd')[0].children[0].getAttribute('data-is-muted') != null){
micMuted = document.querySelectorAll('.GKGgdd')[0].children[0].getAttribute('data-is-muted');
} else {
micMuted = document.querySelectorAll('.GKGgdd')[0].children[0].children[0].getAttribute('data-is-muted');
}
chrome.runtime.sendMessage({ micMuted: micMuted === "true" ? "OFF" : "ON" });
}, 0);
}
window.addEventListener(
"load",
function () {
// console.log("window load called");
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
// console.log("Message", sender.tab ? "from a content script:" + sender.tab.url : "from the extension", request);
if (request.toggleMic) {
if(document.querySelectorAll('.GKGgdd')[0].children[0].getAttribute('data-is-muted')){
micButton = document.querySelectorAll('.GKGgdd')[0].children[0];
} else {
micButton = document.querySelectorAll('.GKGgdd')[0].children[0].children[0];
}
micButton.click();
return true;
} else if (request.listenToMicClick) {
// if(micButton != null){
// micButton.removeEventListener('click',handleMicClick);
// }
if(document.querySelectorAll('.GKGgdd')[0].children[0].getAttribute('data-is-muted')){
micButton = document.querySelectorAll('.GKGgdd')[0].children[0];
} else {
micButton = document.querySelectorAll('.GKGgdd')[0].children[0].children[0];
}
let micMuted = micButton.getAttribute("data-is-muted");
micButton.addEventListener("click", handleMicClick);
// Send response back to the extension so that
// the extension can update the icon in chrome toolbar
sendResponse({
currentMicStatus: micMuted === "true" ? "OFF" : "ON",
});
}
return true;
});
},
false
);