Last active
May 27, 2023 09:34
-
-
Save NegatioN/64b707a32d57a4afd28161affa8fda89 to your computer and use it in GitHub Desktop.
WeDontLikeWastingTime
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
var portalMain = window.frames['mainwindow'].frames['portalmain']; | |
var rightSideFrame; // This is named of the form *_rightside, so we search | |
for(let i = 0; i < portalMain.frames.length; i++) { | |
if(portalMain.frames[i].name.endsWith('_rightside')) { | |
rightSideFrame = portalMain.frames[i]; | |
break; | |
} | |
} | |
var frameDoc = rightSideFrame.frames['componentframe'].document; | |
function getField(frameDoc, col, row) { | |
let weirdIndex = Number('' + col + row); // if there is no value for col, it collapses. eg "01" becomes 1. | |
let elementId = `timeSheetCard:${weirdIndex}`; | |
return frameDoc.getElementById(elementId); | |
}; | |
function setField(frameDoc, col, row, value) { | |
getField(frameDoc, col, row).value = value; | |
}; | |
function setTitle(frameDoc, col, row, value) { | |
getField(frameDoc, col, row).title = value; | |
}; | |
let plannedStartCol = 0; | |
let plannedEndCol = 1; | |
let actualStartCol = 2; | |
let actualEndCol = 3; | |
let workTypeCol = 7; | |
function timeToDate(timestring) { | |
var timeparts = timestring.split(':'); | |
var timedate = new Date(); | |
timedate.setHours(timeparts[0], timeparts[1], 0, 0); | |
return timedate; | |
} | |
var dailyWorkHours = []; | |
for (let x = 0; x < 5; x++) { | |
let expectedStart = getField(frameDoc, x, plannedStartCol).value; | |
let expectedEnd = getField(frameDoc, x, plannedEndCol).value; | |
let workHours = (timeToDate(expectedEnd) - timeToDate(expectedStart)) / (1000 * 60 * 60); | |
dailyWorkHours.push(workHours); | |
setField(frameDoc, x, actualStartCol, expectedStart); | |
setField(frameDoc, x, actualEndCol, expectedEnd); | |
setTitle(frameDoc, x, workTypeCol, 'Fleksitid +/-'); | |
} | |
var row = frameDoc.querySelector('input[title="TDIV000461"]').closest('tr'); | |
Array.from(row.querySelectorAll('td.r')).slice(0, 5).forEach((td, index) => { | |
td.firstChild.value = dailyWorkHours[index]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment