Skip to content

Instantly share code, notes, and snippets.

@fernandovaller
Created December 21, 2021 19:06
Show Gist options
  • Save fernandovaller/5e906658cb16e01160dc02dc5f4cab87 to your computer and use it in GitHub Desktop.
Save fernandovaller/5e906658cb16e01160dc02dc5f4cab87 to your computer and use it in GitHub Desktop.
Script para exportar turmas do LMS
var data = [];
let inputSelect = document.querySelector("#tabObjects > form > div:nth-child(1) > div:nth-child(2) > select");
let trilha = inputSelect[inputSelect.selectedIndex].innerText;
let trilhaID = inputSelect[inputSelect.selectedIndex].value;
let turmas = [];
$('#classList tbody tr.resultSet.classSet').each(function(i, e){
let nome = $(e).find("td:nth-child(1)")[0];
let periodo = $(e).find("td:nth-child(4)")[0];
let status = $(e).find("td:nth-child(5)")[0];
turmas.push({
nome:$.trim(nome.innerHTML),
periodo: $.trim(periodo.innerHTML).replace(/(\r\n|\n|\r)/gm, ""),
status: status
});
});
data.push({
trilha: trilha.innerHTML,
trilha_id: trilhaID,
turmas: turmas
});
// Converte um array em JSON e faz o download do arquivo
function downloadObjectAsJson(exportObj, exportName){
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", exportName + ".json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
}
downloadObjectAsJson(data, trilha);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment