Skip to content

Instantly share code, notes, and snippets.

@jaimergp
Last active February 25, 2023 14:24
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 jaimergp/0cf7cba6c750bff21347f7f7e355ec99 to your computer and use it in GitHub Desktop.
Save jaimergp/0cf7cba6c750bff21347f7f7e355ec99 to your computer and use it in GitHub Desktop.
Add this as a bookmarklet (`javascript:<Paste this gist>`) to add some features to Harvest web UI
var table = document.getElementsByClassName("week-view-table")[0];
table.style.borderCollapse = "collapse";
var trs = document.getElementsByClassName("week-view-entry");
var curr_id = "0";
var curr_cum_hours = 0;
var curr_cum_mins = 0;
var total_length = trs.length;
var i = 0;
function addTotalRow(table, tr, pos, hours, mins) {
var new_row = table.insertRow(pos+1);
new_row.setAttribute("class", tr.getAttribute("class"));
var tds = tr.getElementsByTagName("td");
for (let j = 0; j < tds.length; j++) {
var new_cell = new_row.insertCell(j);
new_cell.setAttribute("class", tds[j].getAttribute("class"));
};
new_row.getElementsByTagName("td")[0].textContent = "Total for project";
var total = `${curr_cum_hours + Math.floor(mins / 60)}:${(mins % 60).toString().padStart(2, '0')}`;
new_row.getElementsByClassName("total")[0].textContent = total;
}
while (i < document.getElementsByClassName("week-view-entry").length) {
var tr = document.getElementsByClassName("week-view-entry")[i];
if (tr.dataset['projectId'] != curr_id) {
if (i > 0) {
tr.style.borderTop = "3px solid black";
addTotalRow(table, tr, i, curr_cum_hours, curr_cum_mins);
total_length += 1;
i += 1;
};
curr_id = tr.dataset['projectId'];
curr_cum_hours = 0;
curr_cum_mins = 0;
};
row_total = tr.getElementsByClassName("total")[0].textContent.trim();
if (row_total != "0") {
curr_cum_hours += parseInt(row_total.split(":")[0]);
curr_cum_mins += parseInt(row_total.split(":")[1]);
};
i += 1;
};
addTotalRow(table, tr, i, curr_cum_hours, curr_cum_mins);
document;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment