Last active
July 1, 2020 08:16
-
-
Save Glutexo/c07cc56085a00d11906094597c97ff9d to your computer and use it in GitHub Desktop.
OrangeHRM timesheet fill-out
This file contains 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 OrangeHRM filler | |
// @version 1.0.0 | |
// @description Simplifies OrangeHRM monthly timesheet submission | |
// @author Glutexo | |
// @homepage https://gist.github.com/Glutexo/c07cc56085a00d11906094597c97ff9d | |
// @match https://*.orangehrm.com/index.php/time/viewTimesheet/mode/my | |
// ==/UserScript== | |
/** | |
* Simplifies OrangeHRM monthly timesheet submission | |
* | |
* Fills in each regular day with the same time (08:00 – 16:30, 00:30 lunch break). | |
* A regular day is a day without special flags: no public holiday, no vacation, | |
* no weekend. | |
*/ | |
(function() { | |
function fillTimeSheet() { | |
var rows = document.querySelectorAll('#timesheetTable .activeRow'); | |
function eachRow(row, _index, _list) { | |
// @TODO Make less cryptic. :) | |
var regularDay = row.classList.length == 1 && row.classList[0] == 'activeRow'; | |
function fillRow() { | |
var inTimeInput = row.querySelector('[name$=\\[inTime\\]]'), | |
outTimeInput = row.querySelector('[name$=\\[outTime\\]]'), | |
breakDurationInput = row.querySelector('[name$=\\[breakDuration\\]]'), | |
event = new MouseEvent('blur'), | |
empty = inTimeInput.value === '' && outTimeInput.value === '' && breakDurationInput.value === ''; | |
// Only empty rows, do not overwrite something special. | |
if (empty) { | |
// 8 hrs of work, ½ hr lunch break | |
inTimeInput.value = '08:00'; | |
outTimeInput.value = '16:30'; | |
breakDurationInput.value = '00:30'; | |
// Must trigger a blur event, so the app counts the working hours for the day. | |
breakDurationInput.dispatchEvent(event); | |
} | |
} | |
// Only regular days, everything else is a special case. | |
if (regularDay) { | |
fillRow(); | |
} | |
} | |
rows.forEach(eachRow); | |
} | |
function init() { | |
var saveButton = document.getElementById('topBtnSave'), | |
formGroup = saveButton.parentNode, | |
fillButton = document.createElement('input'); | |
function buttonClick(event) { | |
event.preventDefault(); | |
fillTimeSheet(); | |
} | |
fillButton.type = 'button'; | |
fillButton.value = 'Fill'; | |
fillButton.classList.add('btn', 'btn-sm', 'rh-grn'); | |
fillButton.addEventListener('click', buttonClick); | |
formGroup.appendChild(fillButton); | |
} | |
init(); | |
})(); |
@slemrmartin Workday script is being born. https://gist.github.com/Glutexo/9776ca630ac33e889fdb63133156dfc3 Prety shitty as for now. It still requires a lot of manual work like blurring all the fields. I‘ll give it some more love next month again. 😆
Great, thanks!
@slemrmartin Continued in https://github.com/Glutexo/workday-timesheet-filler. Blurring is fixed. Still not very automatic, but saves some manual input. Also please note that Workday has an auto-fill function that allows you to copy time entries from previous weeks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@313malek Install Tampermonkey into your browser. Then click its toolbar icon and add a new script. Copy-paste this code into the editor. Feel free to contact me if you have any more questions.