Skip to content

Instantly share code, notes, and snippets.

@SeanMcP
Last active January 18, 2024 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanMcP/155048ebec43c6e30e0aa5fc3b7ff7b8 to your computer and use it in GitHub Desktop.
Save SeanMcP/155048ebec43c6e30e0aa5fc3b7ff7b8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Google Meet Timer
// @namespace https://seanmcp.com
// @version 0.1.1
// @description Adds a simple, chat-powered timer to your Google Meets
// @author Sean McPherson
// @match https://meet.google.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// ==/UserScript==
(function() {
document.querySelectorAll('[data-userscript-gmt]').forEach(n=>n.remove())
// Styles
const style = document.createElement('style')
style.dataset.userscriptGmt = 'styles'
style.innerText = `
[data-userscript-gmt="toolbar"] {
background: hsla(0, 0%, 0%, 75%);
border-radius: 8px;
color: white;
display: flex;
gap: 8px;
left: 50%;
padding: 8px;
position: absolute;
top: 16px;
transform: translateX(-50%);
z-index: 1000;
}
[data-userscript-gmt] span {
font-size: 15px;
}
[data-userscript-gmt] * {
border: none;
border-radius: 4px;
padding: 4px 8px;
font: inherit;
}
[data-userscript-gmt] input {
background-color: #f1f3f4;
color: var(--gm-outlinedtextfield-ink-color,#3c4043);
width: 4ch;
}
[data-userscript-gmt] input[disabled] {
opacity: 0.5;
}
[data-userscript-gmt] button {
background-color: var(--gm-body-text-color);
color: white;
}
`
document.head.appendChild(style)
const toolbar = document.createElement('div')
toolbar.dataset.userscriptGmt = 'toolbar'
document.body.appendChild(toolbar)
const input = document.createElement('input')
input.ariaLabel = 'Minutes'
input.placeholder = "Minutes"
input.type = "number"
input.min = 1
input.max = 30
input.value = 5
toolbar.appendChild(input)
const set = document.createElement('button')
set.textContent = "Set timer"
toolbar.appendChild(set)
const cancel = document.createElement('button')
cancel.textContent = "Cancel timer"
cancel.hidden = true
toolbar.appendChild(cancel)
set.onclick = function(e) {
e.preventDefault();
try {
// Check if the chat window is closed
if (!document.querySelector('[role="heading"][aria-level="1"]')) {
document.querySelector('[aria-label="Chat with everyone"]').click()
}
const textarea = document.querySelector('textarea[aria-label="Send a message to everyone"]')
const submit = document.querySelector('[role="button"][aria-label="Send a message to everyone"]')
function sendMessage(text) {
textarea.click()
textarea.value = text
submit.removeAttribute('aria-disabled')
submit.removeAttribute('disabled')
submit.click()
}
function setTimer(minutes) {
const readableMinutes = `${minutes} minute${minutes != 1 ? 's' : ''}`
sendMessage(`⏳ Timer set for ${readableMinutes}`)
window.googleMeetTimer = setTimeout(()=>{
sendMessage(`🔔 Time is up (${readableMinutes})`)
cleanUp()
}
, 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()
}
})
}
setTimer(input.value)
function cleanUp() {
clearTimeout(window.googleMeetTimer)
clearTimeout(window.googleMeetWarningTimer)
input.removeAttribute('disabled')
set.removeAttribute('hidden')
cancel.hidden = true
}
function cancelTimer(e) {
e.preventDefault()
sendMessage(`🗑 Timer cancelled`)
cleanUp()
}
input.disabled = true
set.hidden = true
cancel.removeAttribute('hidden')
cancel.onclick = cancelTimer
} catch (error) {
alert('Uh oh! Something went wrong setting that timer.')
console.error('Google Meet Timer', error)
}
}
}
)()
@jlrevel
Copy link

jlrevel commented Jan 18, 2024

Hi.
Your script interests me.
But, how do you use it in google meet?

@SeanMcP
Copy link
Author

SeanMcP commented Jan 18, 2024

@jlrevel I haven't used this in a while and it is currently broken 😞

If I get around to fixing it I will notify you with the steps to get it working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment