Skip to content

Instantly share code, notes, and snippets.

@dbrewitz
Last active January 21, 2020 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrewitz/03c04c7cd6cf1127a6bf59b2620abff0 to your computer and use it in GitHub Desktop.
Save dbrewitz/03c04c7cd6cf1127a6bf59b2620abff0 to your computer and use it in GitHub Desktop.
Add total estimated hours, actual hours, and difference in ClickUp
// Client side script to add total estimated hours, actual hours, and difference in ClickUp.com list views
// Use with Custom JS for websites: https://chrome.google.com/webstore/detail/custom-javascript-for-web/ddbjnfjiigjmcpcpkmhogomapikjbjdk?hl=en
function addElement() {
let el = document.querySelector('.lv-body');
if (el) {
elChild = document.createElement('div');
elChild.className = 'totalTime';
elChild.style.textAlign = 'center';
elChild.style.fontWeight = 700;
elChild.style.fontFamily = "var(--global-font-support)";
elChild.style.padding = '20px';
elChild.textContent = 0;
el.appendChild(elChild);
}
}
function insertTotal() {
let myTime = document.querySelectorAll('.time-estimates-view__full-value .cu-task-info__value');
let myActualTime = document.querySelectorAll('.time-tracking__display-time .cu-task-info__value');
console.log(myTime.innerText)
//console.log(myActualTime)
function calcTime(timeArr) {
let sum = 0;
timeArr.forEach((x) => {
// console.log(x)
y = x.textContent.trim();
y = y.split(' ');
if (y[1] == 'mo') {
sum += parseFloat(y[0]) * 30 * 8;
} else if (y[1] == 'w') {
sum += parseFloat(y[0]) * 7 * 8;
} else if (y[1] == 'h') {
sum += parseFloat(y[0]);
if (y[3] == 'm') {
sum += parseFloat(y[2]) / 60;
}
} else if (y[1] == 'd') {
sum += parseFloat(y[0]) * 8;
} else if (y[1] == 'm') {
sum += parseFloat(y[0]) / 60;
}
});
return sum;
}
let myTotal = calcTime(myTime).innerText;
let myActualTotal = calcTime(myActualTime).toFixed(2);
//console.log(myTotal);
//console.log(myActualTotal)
let myTotalTime = document.querySelector('.totalTime');
myTotalTime ? myTotalTime.innerHTML = "<div>" + myTotal + " Hours Estimated -- " + myActualTotal + " Hours Logged -- " + Number(myTotal - myActualTotal).toFixed(2) + " difference </div>" : false;
}
function runTotalScript() {
document.querySelector('.totalTime') ? insertTotal() : addElement();
insertTotal();
}
setInterval(runTotalScript, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment