Skip to content

Instantly share code, notes, and snippets.

@ly4096x
Created November 14, 2021 07:23
Show Gist options
  • Save ly4096x/5020912c4598ebf5b5595aba140d7113 to your computer and use it in GitHub Desktop.
Save ly4096x/5020912c4598ebf5b5595aba140d7113 to your computer and use it in GitHub Desktop.
Teams meeting auto hangup
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://teams.microsoft.com/*
// @icon https://www.google.com/s2/favicons?domain=teams.microsoft.com
// @grant none
// ==/UserScript==
(function () {
class AutoHangClass {
constructor() {
this.maxnumber = 0
this.lastcheckednumber = 0
this.QUIT_THRESHOLD_DIVIDER = 2
this.intervalhandle = null
this.controldiv = undefined
this.running = false
}
getpeople() {
let label = document.querySelectorAll('.roster-list-title')[1].ariaLabel
let splitted = label.split(' ')
if (label.startsWith("Currently in this meeting")) {
return parseInt(splitted[splitted.length - 1])
}
return undefined
}
stopcheck() {
if (this.intervalhandle) {
clearInterval(this.intervalhandle)
this.intervalhandle = null
}
this.controldiv.onclick = 'window.AutoHanger.stopcheck()'
this.controldiv.innerText = 'Q'
this.running = false
this.maxnumber = 0
this.lastcheckednumber = 0
}
doquit() {
console.log('hanging up')
document.querySelector('#hangup-button').click()
this.stopcheck()
}
checkandquit() {
let n = this.getpeople()
console.log(`current remaining: ${n}`)
if (this.running) {
this.controldiv.innerText = `${n}`
}
if (n < this.lastcheckednumber && n < this.maxnumber / this.QUIT_THRESHOLD_DIVIDER) {
this.doquit()
return
}
this.lastcheckednumber = n
if (n > this.maxnumber) {
this.maxnumber = n
}
}
startcheck() {
this.intervalhandle = setInterval(() => this.checkandquit(), 1000)
this.running = true
}
addcontrol() {
let elem = document.createElement('div')
elem.innerHTML = '<div id="controldiv" style="color: #adadad61;position: absolute;bottom: 117px;left: 0;z-index: 99999;">Q</div>'
document.body.append(elem.firstChild)
this.controldiv = document.querySelector('#controldiv')
this.controldiv.addEventListener('click', () => {
if (this.running) {
this.stopcheck()
} else {
this.startcheck()
}
})
}
}
window.AutoHanger = new AutoHangClass()
window.AutoHanger.addcontrol()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment