-
Notifications
You must be signed in to change notification settings - Fork 1
/
google-meet-ptt.js
71 lines (54 loc) · 2.27 KB
/
google-meet-ptt.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
60
61
62
63
64
65
66
67
68
69
70
// ==UserScript==
// @name Google Meet Push-to-Talk
// @namespace dev.josephgeis.gmptt
// @author Joseph Geis
// @homepageURL https://josephgeis.dev/
// @description Makes Space into a Push-to-Talk button, makes Shift a PTT for the camera, and makes Enter a shortcut to the chat window.
// @license MIT
// @version 1.0.2
// @grant none
// @include https://meet.google.com/*
// ==/UserScript==
window.microphoneKey = localStorage.getItem('GMPTT_microphoneKey');
if (window.microphoneKey == null) {
localStorage.setItem('GMPTT_microphoneKey', " ");
window.microphoneKey = " ";
}
window.cameraKey = localStorage.getItem('GMPTT_cameraKey');
if (window.cameraKey == null) {
localStorage.setItem('GMPTT_cameraKey', "Shift");
window.cameraKey = "Shift";
}
window.chatKey = localStorage.getItem('GMPTT_chatKey');
if (window.chatKey == null) {
localStorage.setItem('GMPTT_chatKey', "Enter");
window.chatKey = "Enter";
}
function chatHasFocus() {
return document.querySelector("[id=bfTqV]") === document.activeElement;
}
function microphoneMute(e) {
if (e.key != window.microphoneKey || chatHasFocus()) return;
let unmute = document.querySelector("[data-is-muted='true'][aria-label*='microphone'][role=button]");
const mute = document.querySelector("[data-is-muted='false'][aria-label*='microphone'][role=button]");
if (e.type === "keydown") unmute.click();
if (e.type === "keyup") mute.click();
}
function cameraMute(e) {
if (e.key != window.cameraKey || chatHasFocus()) return;
const unmute = document.querySelector("[data-is-muted='true'][aria-label*='camera'][role=button]");
const mute = document.querySelector("[data-is-muted='false'][aria-label*='camera'][role=button]");
if (e.type === "keydown") unmute.click();
if (e.type === "keyup") mute.click();
}
function chatWindow(e) {
if (e.key != window.chatKey || chatHasFocus()) return;
const chatMenuButton = document.querySelector("button[aria-label*='Chat']");
chatMenuButton.click();
}
window.addEventListener("keydown", microphoneMute);
window.addEventListener("keyup", microphoneMute);
window.addEventListener("keydown", cameraMute);
window.addEventListener("keyup", cameraMute);
window.addEventListener("keydown", chatWindow);
window.addEventListener("keyup", chatWindow);