Last active
July 4, 2025 06:09
-
-
Save Lohann/ea9bf1dcedf85df4358ecfb510f1583d 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
// Script auxiliar para fazer a chamada automaticamente no WebAluno a partir do | |
// arquivo `.csv` gerado pelo Microsoft Teams, para utilizar o script basta logar | |
// no WebAluno e abrir a chamada, então basta copiar e colar a função abaixo no | |
// console do navegador, o script então: | |
// 1 - Irá pedir para vc abrir o Report CSV gerado pelo Microsoft Teams. | |
// 2 - Irá extrair os alunos automaticamente da primeira coluna do CSV. | |
// 3 - Irá marcar as checkbox dos alunos que faltaram, e desmarcar dos que vieram. | |
// 4 - Os nomes que estavam no Teams, mas não na lista de chamada serão reportados no final da execuçãp. | |
// Aproveite! | |
// | |
// Testado em 17/06/2025 no Chrome e Brave. | |
// @Author: Lohann Paterno Coutinho Ferreira <[email protected]> | |
(function() { | |
/// Regex para remover sufixos de nomes, exemplo: | |
/// `Jose da Silva (Unverified)` vira `Jose da Silva` | |
const NOME_REGEX = /^[A-zÀ-ú]+(\s[A-zÀ-ú]+)*/; | |
/// Converte para minusculo, remove espaços em branco e acentos. | |
function normalizeName(name) { | |
name = name.toLowerCase().trim().replaceAll(/\s+/g, ' '); | |
name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, ''); | |
const match = NOME_REGEX.exec(name); | |
if (match === null) { | |
console.log(`${name} -> null`); | |
return null; | |
} | |
return match.length > 0 ? match[0] : name; | |
} | |
/// Marca automaticamente os alunos que faltaram, desmarca os alunos que apareceram. | |
function fazerChamada(nomesCSV) { | |
const chamada = { | |
presentes: [], // Alunos presentes | |
faltou: [], // Alunos que faltaram | |
naoEncontrados: [], // Nomes que não constam na chamada | |
}; | |
const todosAlunos = (function () { | |
// Lista todos os alunos a partir da página HTML. | |
let el = document.getElementById('edicao'); | |
el = el.children[el.children.length - 1]; | |
el = el.children[0]; | |
el = el.children[0]; | |
return Array.from(el.children) | |
.filter((r) => r.className.startsWith('cinza')) | |
.map((r) => { | |
const nome = r.children[1].children[1].childNodes[1].textContent; | |
const checkbox = r.children[0].children[1]; | |
return [nome, checkbox]; | |
}); | |
})(); | |
for (let i=0; i<todosAlunos.length; i++) { | |
let [nome, checkbox] = todosAlunos[i]; | |
nome = normalizeName(nome); | |
const isPresent = nomesCSV.has(nome); | |
if (isPresent) { | |
chamada.presentes.push(nome); | |
nomesCSV.delete(nome); | |
} else { | |
chamada.faltou.push(nome); | |
} | |
if (isPresent === (!!checkbox.checked)) { | |
setTimeout(() => { | |
checkbox.click(); | |
}); | |
} | |
} | |
chamada.naoEncontrados = Array.from(nomesCSV); | |
if (chamada.naoEncontrados.length > 0) { | |
const mensagem = Array.from(nomesCSV).join('\n - '); | |
setTimeout(() => { | |
window.alert(`alunos não encontrados:\n - ${mensagem}`); | |
}); | |
} | |
return chamada; | |
}; | |
/// Extrai o nome dos alunos a partir do arquivo CSV. | |
function extrairCSV(csvContent) { | |
const lines = csvContent.split('\n'); | |
const names = new Set(); | |
let line, i, name; | |
for (i=0; i<lines.length; i++) { | |
if (lines[i].startsWith('2. Participants')) break; | |
} | |
for (i += 2; i<lines.length; i++) { | |
line = lines[i].split('\t'); | |
if (line.length < 6) { | |
break; | |
} | |
name = normalizeName(line[0]); | |
if (name && name.length > 0) { | |
names.add(name); | |
} | |
} | |
return names; | |
} | |
// Abre o filepicker para escolher o arquivo CSV gerado pelo Microsoft Teams | |
function abrirCSV() { | |
const dialog = document.createElement('input'); | |
dialog.style.display = 'none'; | |
dialog.type = 'file'; | |
dialog.accept = '.csv'; | |
dialog.onchange = function(event) { | |
if (!this.files || this.files.length === 0) { | |
return; | |
} | |
const url = window.URL.createObjectURL(this.files[0]); | |
const reader = new FileReader(); | |
reader.onload = function (e) { | |
const alunos = extrairCSV(reader.result); | |
console.log(fazerChamada(alunos)); | |
}; | |
reader.readAsText(this.files[0], 'utf-16le'); | |
}; | |
document.body.appendChild(dialog); | |
setTimeout(function() { dialog.click(); }); | |
} | |
// Executa o script imediatamente se a página já carregou. | |
if (document.readyState === 'complete' || document.readyState === undefined) { | |
abrirCSV(); | |
return; | |
} | |
// Executa o script assim que a página carregar. | |
const onLoad = document.onload; | |
document.onload = function(event) { | |
if (onLoad) onLoad(event); | |
abrirCSV(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment