Skip to content

Instantly share code, notes, and snippets.

@ivanlonel
Last active April 11, 2023 21:51
Show Gist options
  • Save ivanlonel/07fdbc1c97bb418b2030daf252ee786d to your computer and use it in GitHub Desktop.
Save ivanlonel/07fdbc1c97bb418b2030daf252ee786d to your computer and use it in GitHub Desktop.
Preencher Acompanhamento das Atividades - PGD
// ==UserScript==
// @name Preencher Acompanhamento das Atividades - PGD
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Preenche automaticamente os campos "Status", "Início", "Fim" e "Tempo gasto para realizar a atividade" da página de acompanhamento das atividades do PGD
// @author ChatGPT
// @match http://w3.programagestao.sda.ibge.gov.br/SDA-ProgramaGestao/planoTrabalho.jsf
// @icon https://www.google.com/s2/favicons?sz=64&domain=gov.br
// @grant none
// ==/UserScript==
(function () {
'use strict';
function preencherAcompanhamento() {
// iterar sobre cada atividade do plano do mês
document.querySelectorAll("div > table.tabelaPadding5").forEach(element => {
// altera o valor do dropdown "Status" para "REALIZADA"
const dropdown = element.querySelector("td.alinhamentoVerticalTopo > select");
dropdown.value = "REALIZADA";
// dropdown.dispatchEvent(new Event('change'));
// obter o valor (texto) do campo "Tempo Total:"
let tempoTotal;
for (const td of element.querySelectorAll("td")) {
if (td.textContent.trim() === "Tempo Total:") {
tempoTotal = td.nextElementSibling.querySelector("span.campoConsulta").textContent.trim();
break;
}
}
// extrair o tempo (convertendo em minutos) do texto obtido
const [horas_str] = tempoTotal.match(/^(\d+)/);
const minutos = (horas_str ? parseInt(horas_str) : 0) * 60;
// editar valor do input "Tempo gasto para realizar a atividade"
const tempoInput = element.querySelector("td.alinhamentoVerticalTopo > input");
tempoInput.value = `${String(Math.floor(minutos / 60)).padStart(2, '0')}:${String(minutos % 60).padStart(2, '0')}`;
tempoInput.dispatchEvent(new Event('change'));
// obter mês e ano
const monthYear = element.querySelector("div.rf-cal > span:first-child input[type='hidden']").value.trim();
const [month, year] = monthYear.split("/");
// editar valor do input "Início" para o dia 1 do mês e ano obtidos acima (dd/mm/yyyy)
element.querySelector("div.rf-cal > span:first-child input[type='text']").value = `01/${month}/${year}`;
// editar valor do input "Fim" para o último dia do mês e ano obtidos acima (dd/mm/yyyy)
const endDateInput = element.querySelectorAll("div.rf-cal > span:first-child input[type='text']")[1];
endDateInput.disabled = false;
endDateInput.value = new Date(year, month, 0).toLocaleDateString('pt-BR');
});
}
// criar um botão para executar a função acima
const button = document.createElement("button");
button.innerHTML = "PREENCHER AUTOMATICAMENTE";
button.style.position = "fixed";
button.style.top = "10px";
button.style.left = "10px";
button.style.zIndex = "9999";
button.addEventListener("click", preencherAcompanhamento);
// adicionar botão ao HTML da página
document.body.appendChild(button);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment