Forked from raxoft/convert-ks-portal-hours-to-days.js
Last active
March 19, 2021 08:03
-
-
Save sadovsf/230f114c3837656847ddf422250db229 to your computer and use it in GitHub Desktop.
Little script to show hours in KS portal both as hours and days.
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 Show KS portal hours as days | |
// @version 9 | |
// @author [email protected] and [email protected] | |
// @updateURL https://gist.githubusercontent.com/sadovsf/230f114c3837656847ddf422250db229/raw | |
// @include https://ks.scssoft.com/ksportal/* | |
// ==/UserScript== | |
const handle_cell = function(el) { | |
const text_parts = el.textContent.replace(/,/g,'.').split('/'); | |
let hours = Number(text_parts[0]); | |
if (text_parts.length > 1) { | |
const last_year = Number(text_parts[1]); | |
if (! isNaN(last_year)) { | |
hours += last_year * 8.0; | |
} | |
} | |
const days = Math.ceil(hours * 10 / 8.0) / 10.0; | |
el.textContent = hours.toString() + "h = " + days.toString() + "d"; | |
} | |
const handle_section = function(section_name) { | |
const content = document.querySelectorAll(`#${section_name} .boxview-obsah span`); | |
for(let el of content) { | |
handle_cell(el); | |
} | |
const content_sizing = document.querySelectorAll(`#${section_name} .boxview-okno, .boxview-okno-posledni`); | |
for(let el of content_sizing) { | |
el.style.width = '300px'; | |
} | |
const content_header_sizing = document.querySelectorAll(`#${section_name} .boxview-nadpis`); | |
for(let el of content_header_sizing) { | |
el.style.width = '290px'; | |
} | |
} | |
handle_section('ctl00_HlavniOblast_BV_Dovolena'); | |
handle_section('ctl00_HlavniOblast_BV_DovolenaPozadavky'); | |
// Sickdays are in days so dont handle them. | |
//handle_section('ctl00_HlavniOblast_BV_SickDays'); | |
const requests = document.querySelectorAll('td[id*="FormView1"][id*="_hodin"] span'); | |
for (let el of requests) { | |
if (! el.textContent.match(/^[0-9\,\/ ]+$/)) { | |
continue; | |
} | |
handle_cell(el); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment