Last active
November 19, 2024 17:27
-
-
Save ameboide/9826f5b32816cfa432c55e92a93e22b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name Meet 🎤 / 🎥 | |
// @namespace ameboide | |
// @version 0.11 | |
// @description muestra 🎤 y/o 🎥 en title, 🔈/🔉/🔊 si alguien habla, y loggea los cc | |
// @author ameboide | |
// @match https://meet.google.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let textByAuthor = {}; | |
function check(){ | |
checkIcon(["Turn off microphone", "Turn off microphone (ctrl + d)", "Desactivar micrófono", "Desactivar micrófono (Ctrl + d)"], '🎤'); | |
checkIcon(["Turn off camera", "Turn off camera (ctrl + e)", "Desactivar cámara", "Desactivar cámara (Ctrl + e)"], '🎥'); | |
checkSoundIcon(); | |
logTranscription(); | |
} | |
function checkIcon(labels, prefix){ | |
let selector = labels.map((label) => `[aria-label="${label}"]`).join(','); | |
setIcon(prefix, document.querySelector(selector)); | |
} | |
function setIcon(icon, show){ | |
let title = document.title; | |
let visible = title.indexOf(icon) >= 0; | |
if(show && !visible){ | |
document.title = `${icon} ${title}`; | |
} | |
else if(!show && visible){ | |
document.title = title.replace(`${icon} `, ''); | |
} | |
} | |
function checkSoundIcon(){ | |
let soundIcon = ''; | |
if (document.querySelector('.JHK7jb.Nep7Ue:not(.FTMc0c)')){ | |
soundIcon = '🔈'; | |
if(document.querySelector('.IisKdb.YFyDbd:not(.gjg47c)')) soundIcon = '🔊'; | |
else if(document.querySelector('.atLQQ.kssMZb')) soundIcon = '🔉'; | |
} | |
for(let i of ['🔈', '🔉', '🔊']) setIcon(i, soundIcon == i); | |
} | |
function logTranscription(){ | |
let texts = groupedTranscription(); | |
for(let author in textByAuthor){ | |
let newText = texts[author]; | |
let oldText = textByAuthor[author]; | |
if(!newText){ | |
printLog(author, oldText); | |
delete textByAuthor[author]; | |
continue; | |
} | |
let updated = removeOverlap(oldText, newText); | |
if(!updated){ | |
printLog(author, oldText); | |
textByAuthor[author] = newText; | |
} else { | |
textByAuthor[author] = updated; | |
} | |
} | |
for(let author in texts){ | |
if(!textByAuthor[author]){ | |
textByAuthor[author] = texts[author]; | |
} | |
} | |
} | |
function clean(text){ | |
return text.toUpperCase().replace(/\W+/g, ''); | |
} | |
function groupedTranscription(){ | |
let divs = Array.from(document.querySelectorAll('[jsname="dsyhDe"] > div')); | |
return Object.fromEntries(divs.map((div) => | |
Array.from(div.querySelectorAll(':scope > div')).map((d) => d.textContent) | |
)); | |
} | |
function removeOverlap(t1, t2){ | |
let overlap = clean(t1); | |
let ct2 = clean(t2); | |
while(overlap && ct2.indexOf(overlap) != 0) overlap = overlap.substr(1); | |
if(!overlap) return; | |
let t1len = t1.length - 1; | |
let olen = overlap.length; | |
for(let w = 0; w < olen; t1len--) if(t1[t1len].match(/\w/)) w++; | |
return t1.substr(0, t1len + 1) + t2; | |
} | |
function printLog(author, text){ | |
if(!text || !clean(text)) return; | |
console.log(`${new Date().toLocaleTimeString()} | ${author}: ${text}`); | |
} | |
setInterval(check, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment