Forked from SeanMcP/google-meet-timer.console.js
Last active
January 18, 2024 14:15
-
-
Save MikeRawding/aab147a3963b629c9efd04bc35717181 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"]') | |
let submit = document.querySelector('[role="button"][aria-label="Send a message"]') | |
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) | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment