Skip to content

Instantly share code, notes, and snippets.

@derkork
Created December 14, 2018 06:59
Show Gist options
  • Save derkork/ed0d827c057e38bcdabdfe556c04ddb9 to your computer and use it in GitHub Desktop.
Save derkork/ed0d827c057e38bcdabdfe556c04ddb9 to your computer and use it in GitHub Desktop.
Casual PM: Sum up remaining effort tampermonkey script
// ==UserScript==
// @name Calculate remaining effort
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Sums of the effort of all tasks that are not yet finished. 1 day is counted as 8 hours.
// @author Jan Thomä
// @match https://app.casual.pm/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function toSeconds(value) {
if (value === null) {
return 0;
}
var regex = /^(([0-9]+)d *)?(([0-9]+)h *)?(([0-9]+)m *)?$/;
var match = regex.exec(value);
if (match === null) {
return 0;
}
var days = 0;
var hours = 0;
var minutes = 0;
if (match[1]) {
days += parseInt(match[2]);
}
if (match[3]) {
hours += parseInt(match[4]);
}
if (match[5]) {
minutes += parseInt(match[6]);
}
return (days * 8 * 3600) + (hours * 3600) + (minutes * 60);
}
function toPersonDays(seconds) {
return seconds / 8 / 3600;
}
function calculate() {
var efforts = document.querySelectorAll("text.g11g");
var effortSeconds = 0;
for(var i = 0; i < efforts.length; i++) {
effortSeconds += toSeconds(efforts[i].textContent);
}
alert("Remaining effort is " + toPersonDays(effortSeconds) + " person days." );
}
function install() {
var existingButton = document.querySelector("div.feedback-link");
if (existingButton == null) {
console.log("not yet ready...");
window.setTimeout(install, 500);
return;
}
var button = document.createElement('div');
button.setAttribute("class", "feedback-link");
button.setAttribute("style", "padding-right: 20px; margin-right: 5px;");
button.textContent = "Remaining effort";
button.onclick = calculate;
existingButton.parentNode.insertBefore(button, existingButton);
}
install();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment