Skip to content

Instantly share code, notes, and snippets.

@ameboide
Last active April 22, 2024 16:55
Show Gist options
  • Save ameboide/9826f5b32816cfa432c55e92a93e22b2 to your computer and use it in GitHub Desktop.
Save ameboide/9826f5b32816cfa432c55e92a93e22b2 to your computer and use it in GitHub Desktop.
// ==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