Skip to content

Commit c7a73c1

Browse files
committed
feat(aditro): add Flex Fix user script for SD Worx integration
Format flex time entries in the calendar view for better readability and log total flex hours in the console.
1 parent e8f27c4 commit c7a73c1

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ My collection of Tampermonkey scripts.
1414
- [🛠️ Jira Board Utils](#️-jira-board-utils)
1515
- [Features](#features-1)
1616
- [How it works](#how-it-works-1)
17+
- [🧾 Aditro: HR Calendar Flex Fix](#-aditro-hr-calendar-flex-fix)
1718
- [🛠️ Development](#️-development)
1819
- [Local Development Server](#local-development-server)
1920
- [💖 Support](#-support)
@@ -143,6 +144,21 @@ Access settings through by clicking the cogwheel icon. Located next to the "Crea
143144

144145
---
145146

147+
### 🧾 Aditro: HR Calendar Flex Fix
148+
149+
**Description:** Cleans up and highlights flexible working hour entries on Aditro/HR calendar pages. The script normalizes verbose transaction text to a compact `Flex in/out X.XX h`, applies color styling, and prints a small console summary of total flex hours.
150+
151+
- **Script:** `scripts/aditro.js`
152+
- **Match:** `https://hr.aditro.com/*`
153+
- **Features:**
154+
- Normalizes calendar transaction text to `Flex in` / `Flex out` with hours
155+
- Applies green/red styling to entries for quick visual scanning
156+
- Calculates total flex and logs a console table with day/type/hours
157+
- Runs on a 3s interval to update dynamically loaded content
158+
- **Install:** Add the script via Tampermonkey using the raw URL:
159+
- https://github.com/scharinger/userscripts/raw/refs/heads/main/scripts/aditro.js
160+
161+
146162
## 🛠️ Development
147163

148164
### Local Development Server

docs/aditro.png

565 KB
Loading

scripts/aditro.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// ==UserScript==
2+
// @name SD Worx / Aditro - Flex Fix
3+
// @namespace https://github.com/scharinger/userscripts
4+
// @version 2.2
5+
// @description Format flex time entries in the calendar view for better readability and log total flex hours in the console.
6+
// @author Tim Scharinger
7+
// @match https://hr.aditro.com/*
8+
// @donate https://ko-fi.com/scharinger
9+
// @grant none
10+
// ==/UserScript==
11+
12+
(function() {
13+
'use strict';
14+
15+
const STYLE = {
16+
IN: { color: "#155724", bg: "#d4edda", border: "#c3e6cb", label: "Flex in" },
17+
OUT: { color: "#721c24", bg: "#f8d7da", border: "#f5c6cb", label: "Flex out" }
18+
};
19+
20+
window.runCalendarFix = function() {
21+
const transactions = document.querySelectorAll('.calendar-day-transaction');
22+
if (!transactions.length) return;
23+
24+
let totalFlex = 0;
25+
const data = [];
26+
27+
transactions.forEach(tr => {
28+
const infoTextEl = tr.querySelector('.information-string-text');
29+
if (!infoTextEl) return;
30+
31+
const originalText = infoTextEl.innerText || "";
32+
const isFlexIn = originalText.includes("376");
33+
const isFlexOut = originalText.includes("377");
34+
35+
if (isFlexIn || isFlexOut) {
36+
const config = isFlexIn ? STYLE.IN : STYLE.OUT;
37+
38+
// 1. EXTRACT HOURS
39+
const matches = originalText.match(/(\d+[.,]\d+)|(\d+)/g);
40+
const val = matches ? parseFloat(matches[matches.length - 1].replace(',', '.')) : 0;
41+
42+
// 2. UPDATE TEXT IN THE CALENDAR
43+
// Converts "FLEXIBLE WORKING HOURS OUT 377 1.50 Hours" -> "Flex out 1.50 h"
44+
infoTextEl.innerText = `${config.label} ${val.toFixed(2)} h`;
45+
46+
// 3. STYLE THE BOX
47+
const body = tr.querySelector('.transaction-body');
48+
if (body) {
49+
body.style.setProperty('background-color', config.bg, 'important');
50+
body.style.setProperty('color', config.color, 'important');
51+
body.style.setProperty('border', `1px solid ${config.border}`, 'important');
52+
body.style.setProperty('background-image', 'none', 'important');
53+
body.style.setProperty('padding', '2px 5px', 'important'); // Slightly more compact
54+
}
55+
56+
tr.style.setProperty('border-left', `5px solid ${isFlexIn ? '#28a745' : '#dc3545'}`, 'important');
57+
58+
// 4. COLLECT DATA FOR THE CONSOLE
59+
const dayContainer = tr.closest('calendar-day');
60+
let dayNum = "??";
61+
if (dayContainer) {
62+
const dateEl = dayContainer.querySelector('.calendar-day-date span:first-child');
63+
if (dateEl) dayNum = dateEl.innerText.trim();
64+
}
65+
66+
if (isFlexOut) totalFlex -= val;
67+
else totalFlex += val;
68+
69+
data.push({ Day: dayNum, Type: config.label, Hours: val.toFixed(2) });
70+
}
71+
});
72+
73+
if (data.length > 0) {
74+
console.clear();
75+
const logColor = totalFlex >= 0 ? '#28a745' : '#dc3545';
76+
console.log(`%c TOTAL FLEX: ${totalFlex.toFixed(2)}h `,
77+
`background: ${logColor}; color: white; font-size: 16px; font-weight: bold; padding: 5px; border-radius: 3px;`);
78+
console.table(data);
79+
}
80+
};
81+
82+
setInterval(window.runCalendarFix, 3000);
83+
})();

0 commit comments

Comments
 (0)