Last active
April 22, 2024 16:55
-
-
Save ameboide/9826f5b32816cfa432c55e92a93e22b2 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Meet ๐ค / ๐ฅ | |
// @namespace ameboide | |
// @version 0.8 | |
// @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 (ctrl + d)", "Desactivar micrรณfono (Ctrl + d)"], '๐ค'); | |
checkIcon(["Turn off camera (ctrl + e)", "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){ | |
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