Google Meet Push-to-Talk

Makes Space into a Push-to-Talk button, makes Shift a PTT for the camera, and makes Enter a shortcut to the chat window.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);