Last active
November 4, 2020 10:55
-
-
Save paulera/e23462f76299f61e760a43140fc74f52 to your computer and use it in GitHub Desktop.
Generate a list of participants, with check-in time
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
// run this in the console | |
// call copyAttendanceListToClipboard() in the console to get the list. | |
function initializeAttendanceList() { | |
window.attendanceMap = new Map(); | |
} | |
function computeParticipants() { | |
var elements = document.querySelectorAll("div[data-self-name]"); | |
for (var item of elements) { | |
var name = item.innerHTML; | |
if (name != "You" && !window.attendanceMap.has(name)) { | |
var now = new Date().toLocaleTimeString([], { hour: '2-digit', minute: "2-digit", hour12: false }); | |
window.attendanceMap.set (name, now); | |
console.log ("Attendance: " + name + " joined at " + now); | |
} | |
} | |
return window.attendanceMap; | |
} | |
function abortGetAttendance() { | |
if (window.attendanceListTimer) { | |
clearInterval(window.attendanceListTimer); | |
console.log ("Attendance timer killed"); | |
} | |
window.attendanceListTimer = null; | |
} | |
function startComputeAttendance() { | |
if (window.attendanceListTimer) { | |
abortGetAttendance(); | |
} | |
computeParticipants(); | |
window.attendanceListTimer = setInterval (computeParticipants, 15000); | |
console.log ("Attendance timer started"); | |
} | |
function renderAttendanceList() { | |
var attendanceList = ""; | |
for (var item of window.attendanceMap) { | |
attendanceList += item[1] + "\t" + item[0] + "\n"; | |
}; | |
return attendanceList; | |
} | |
function copyAttendanceListToClipboard () { | |
navigator.clipboard.writeText(renderAttendanceList()); | |
alert("Attendance list copied to the clipboard"); | |
} | |
initializeAttendanceList(); | |
startComputeAttendance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment