Last active
May 17, 2022 17:13
-
-
Save SeanMcP/b71b8765fc085b7c0db473c83583a6af to your computer and use it in GitHub Desktop.
Sets a timer for Google Meet with chat messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function() { | |
let textarea = document.querySelector('textarea[aria-label="Send a message to everyone"]') | |
let submit = document.querySelector('[role="button"][aria-label="Send a message to everyone"]') | |
if (!textarea || !submit) | |
return alert('Uh oh! Something went wrong. Do you have the chat panel open?') | |
function sendMessage(text) { | |
textarea.click() | |
textarea.value = text | |
submit.removeAttribute('aria-disabled') | |
submit.removeAttribute('disabled') | |
submit.click() | |
} | |
function setTimer(minutes) { | |
let readableMinutes = `${minutes} minute${minutes !== 1 ? 's' : ''}` | |
sendMessage(`⏳ Timer set for ${readableMinutes}`) | |
window.googleMeetTimer = setTimeout(()=>{ | |
sendMessage(`🔔 Time is up (${readableMinutes})`) | |
} | |
, minutes * 60 * 1000) | |
if (minutes >= 2) { | |
window.googleMeetWarningTimer = setTimeout(()=>{ | |
sendMessage(`⌛️ One minute left`) | |
} | |
, (minutes - 1) * 60 * 1000) | |
} | |
window.addEventListener('keydown', function(event) { | |
if (event.key === 'Backspace' && event.ctrlKey && event.shiftKey) { | |
cancelTimer() | |
} | |
}) | |
} | |
function cancelTimer() { | |
sendMessage(`🗑 Timer cancelled`) | |
clearTimeout(window.googleMeetTimer) | |
clearTimeout(window.googleMeetWarningTimer) | |
} | |
let container = document.querySelector('[role="heading"][aria-level="1"]') | |
let timerContainer = document.createElement('div') | |
let button = document.createElement('button') | |
button.textContent = 'Set Timer' | |
let input = document.createElement('input') | |
input.type = 'number' | |
input.value = 5 | |
input.style = "width: 50px" | |
timerContainer.appendChild(input) | |
timerContainer.appendChild(button) | |
container.appendChild(timerContainer) | |
button.addEventListener('click', ()=>{ | |
setTimer(input.value) | |
let cancelButton = document.createElement('button') | |
cancelButton.textContent = 'Cancel Timer' | |
cancelButton.addEventListener('click', ()=>{ | |
cancelTimer() | |
cancelButton.remove() | |
} | |
) | |
timerContainer.appendChild(cancelButton) | |
} | |
) | |
} | |
)() |
Hi @SeanMcP! I needed to update a selector, but gists don't seem to really allow collaboration. I forked this and got it working again :) Feel free to steal my changes if you want to keep your version working.
Thanks @MikeRawding! I made those changes 👍
I'm moving the development of this feature to a userscript. Feel free to fork this if you want to continue iterating on the console script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@gtelljohann Fixed!