Created
May 27, 2023 13:27
-
-
Save MaxMatti/a4c92d838c852297ac24d70a9c4a53e6 to your computer and use it in GitHub Desktop.
Tampermonkey userscript for Kimai to list the each months expected payment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name PayCount | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description List each months expected payment | |
// @author You | |
// @match https://yourdomain.com/timesheet/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=yourdomain.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function finishUp(count, sumRect) { | |
let rect = table.tHead.children[0].children[6].getBoundingClientRect(); | |
let div = document.createElement("div"); | |
div.style.borderStyle = "solid"; | |
div.style.borderColor = "#f00"; | |
div.style.borderWidth = "2px"; | |
div.style.position = "absolute"; | |
div.style.top = sumRect.top + "px"; | |
div.style.left = sumRect.left + "px"; | |
div.style.height = sumRect.bottom - sumRect.top + "px"; | |
div.style.width = sumRect.right - sumRect.left + "px"; | |
document.body.appendChild(div); | |
let label = document.createElement("label"); | |
label.innerHTML += count + " €"; | |
label.style.display = "block"; | |
label.style.textAlign = "right"; | |
label.style.position = "absolute"; | |
label.style.top = sumRect.bottom - 4 + "px"; | |
label.style.left = sumRect.left + "px"; | |
label.style.width = sumRect.right - sumRect.left + "px"; | |
document.body.appendChild(label); | |
} | |
let currentMonth = new Date().getMonth() + 1; | |
let table = document.querySelector("table.table.table-hover.dataTable"); | |
let rows = table.tBodies[0].children; | |
let count = 0.0; | |
let sumRect = {'top': Infinity, 'bottom': 0, 'left': Infinity, 'right': 0}; | |
for (let row of rows) { | |
let rowMonth = parseInt(row.children[1].innerText.replace(/(\d{2})\.(\d{2})\.(\d{4})/, '$2'), 10); | |
if (rowMonth != currentMonth) { | |
row.style.borderTop = "10px solid transparent"; | |
finishUp(count, sumRect); | |
count = 0.0; | |
sumRect = {'top': Infinity, 'bottom': 0, 'left': Infinity, 'right': 0}; | |
currentMonth = rowMonth; | |
} | |
let rowCount = parseFloat(row.children[6].innerText.replace(',', '.').replace('€', '').trim()); | |
if (!isNaN(rowCount)) { | |
count += rowCount; | |
} | |
let rowCountRect = row.children[6].getBoundingClientRect(); | |
sumRect.top = Math.min(sumRect.top, rowCountRect.top + 10); | |
sumRect.left = Math.min(sumRect.left, rowCountRect.left); | |
sumRect.bottom = Math.max(sumRect.bottom, rowCountRect.bottom - 10); | |
sumRect.right = Math.max(sumRect.right, rowCountRect.right); | |
} | |
finishUp(count, sumRect); | |
// Your code here... | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After installing this you still need to adjust the domain/url to whatever your kimai instance has.