Skip to content

Instantly share code, notes, and snippets.

@marcusedu
Created April 1, 2022 14:52
Show Gist options
  • Save marcusedu/1db329074bfd2f9cf8bd5e36a4e4ef20 to your computer and use it in GitHub Desktop.
Save marcusedu/1db329074bfd2f9cf8bd5e36a4e4ef20 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Dias Atividade
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adiciona indicador de dias para conclusão da atividade
// @author Marcus Duarte<marcusedu@hotmail.com>
// @match https://colaboraread.com.br/aluno/timeline/index/*
// @icon https://www.google.com/s2/favicons?domain=colaboraread.com.br
// @grant none
// ==/UserScript==
(function() {
'use strict';
function date_diff_indays(date1, date2) {
let dt1 = new Date(date1);
let dt2 = new Date(date2);
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()) ) /(1000 * 60 * 60 * 24));
}
[...document.getElementsByClassName('text-muted')].filter((e)=>e.childElementCount == 2).filter((e)=>e.textContent.includes('Período')).forEach(e => {
var deadlineList = e.textContent.trim().substr(-8).split('/').map(e=>parseInt(e));
var deadline = new Date(deadlineList[2]+2000,deadlineList[1]-1,deadlineList[0]);
var bNode = document.createElement("STRONG");
let days = date_diff_indays(Date(),deadline);
if (days < 0) {
bNode.style.color = 'red';
} else if(days > 0 && days < 2){
bNode.style.color = 'yellow';
} else if(days > 2) {
bNode.style.color = 'green';
}
bNode.appendChild(document.createTextNode(" ("+days+")"));
e.appendChild(bNode);
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment