Last active
December 27, 2021 12:58
-
-
Save fernandovaller/e59b5a6534b2d0d2a5264018010efd08 to your computer and use it in GitHub Desktop.
Script para exportar etapas e arquivos das trilhas do LMS
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
let nome_curso = ($('h1.cor1_color span').text()).replaceAll(':', ''); | |
nome_curso = $.trim(nome_curso); | |
let trilha = document.querySelector("#select2-chosen-5").innerText; | |
nome_curso = `${nome_curso}-${trilha}`; | |
var etapa_itens = []; | |
var data = []; | |
$('li.stepContainer').each(function(i, e){ | |
etapa_itens = []; | |
let etapa = $(e).find('.stepTitle input')[0]; | |
let itens = $(e).find('.trailListItem .itemText h3.textOverflowEllipsis'); | |
itens.each(function(index, el){ | |
etapa_itens.push($.trim(el.textContent)); | |
}); | |
data.push({etapas: `${etapa.value}`, itens: etapa_itens}); | |
}); | |
// 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, nome_curso); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment