Update stomp.js

This commit is contained in:
Lorenz Hohermuth 2024-10-21 11:16:49 +02:00
parent 821b1bb1e8
commit 677bdf7cd4
1 changed files with 11 additions and 27 deletions

View File

@ -1,8 +1,8 @@
// ==UserScript== // ==UserScript==
// @name stomp // @name stomp
// @namespace https://github.com/dmtbz // @namespace https://git.bsiag.com/dmi
// @source https://github.com/dmtbz/stomp // @source https://git.bsiag.com/dmi/stomp
// @version 1.4 // @version 1.3.1
// @description try to take over the world! // @description try to take over the world!
// @author You // @author You
// @match https://services.bsi-software.com/bsicrm/* // @match https://services.bsi-software.com/bsicrm/*
@ -24,71 +24,55 @@ function doc_keyUp(e) {
var headers = document.getElementsByClassName("table-header-item-text"); var headers = document.getElementsByClassName("table-header-item-text");
var columnPosBuchungstext; var columnPosBuchungstext;
var columnPosHours; var columnPosHours;
var columnPosActivity;
const emptyCellClassName = "table-cell white-space-nowrap halign-left table-aggregate-cell empty";
for (let i = 0; i < headers.length; i++) { for (let i = 0; i < headers.length; i++) {
if (headers[i]) { if (headers[i]) {
if (headers[i].textContent.match(/Buchungstext/gm)) { if (headers[i].textContent.match(/Buchungstext/gm)) {
columnPosBuchungstext = i; columnPosBuchungstext = i;
} else if (headers[i].textContent.match(/Dauer \[h]/gm)) { } else if (headers[i].textContent.match(/Dauer \[h]/gm)) {
columnPosHours = i; columnPosHours = i;
} else if (headers[i].textContent.match(/Aktivität/gm)) {
columnPosActivity = i;
} }
} }
} }
var startpos; var startpos;
var nodes = document.getElementsByClassName("table-row leaf first")[0].parentNode.children; var nodes = document.getElementsByClassName("table-row first")[0].parentNode.children;
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
if (nodes[i].className.match(/table-row leaf (?:selected select-single )?first/g)) { if (nodes[i].className.match(/table-row (?:selected select-single )?first/g)) {
startpos = i; startpos = i;
break; break;
} }
} }
// 0800-1200/1245-1700[] // 0800-1200/1245-1700[]
var totalTimeMinutes;
for (let i = startpos; i < nodes.length - 1; i++) { for (let i = startpos; i < nodes.length - 1; i++) {
let node = nodes[i].childNodes[columnPosBuchungstext]; let node = nodes[i].childNodes[columnPosBuchungstext];
let text = node.textContent; let text = node.textContent;
if (text && text.match(/^[0-9]{4}-[0-9]{4}(?:\/[0-9]{4}-[0-9]{4})?(?:\[[-]?[0-9]{0,2}\])?/gm)) { if (text && text.match(/^[0-9]{4}-[0-9]{4}(?:\/[0-9]{4}-[0-9]{4})?(?:\[[-]?[0-9]{0,2}\])?/gm)) {
let morning = getMinutes(text.substring(0, 4), text.substring(5, 9)); let morning = getMinutes(text.substring(0, 4), text.substring(5, 9));
let afternoon = getMinutes(text.substring(10, 14), text.substring(15, 19)); let afternoon = getMinutes(text.substring(10, 14), text.substring(15, 19));
let stampMinutes = morning + afternoon + parseInt(text.match(/\[([-]?[0-9]+)\]/)[1]); totalTimeMinutes =+ morning + afternoon + parseInt(text.match(/\[([-]?[0-9]+)\]/)[1]);
let n = i; let n = i;
while (nodes[n].childNodes[columnPosBuchungstext].className != emptyCellClassName) { while (nodes[n].childNodes[columnPosBuchungstext].className != "table-cell white-space-nowrap halign-left table-aggregate-cell empty") {
n--; n--;
} }
let sumNode = nodes[n].childNodes[columnPosHours]; let sumNode = nodes[n].childNodes[columnPosHours];
let actualNode = nodes[n].childNodes[columnPosBuchungstext]; let actualNode = nodes[n].childNodes[columnPosBuchungstext];
let workSum = nodes[n].childNodes[columnPosHours].getElementsByClassName("text")[0].textContent.split("."); let workSum = nodes[n].childNodes[columnPosHours].getElementsByClassName("text")[0].textContent.split(".");
let actualMinutes = toMinutes(parseInt(workSum[0]), parseInt(workSum[1] / 100 * 60)); let workSumMinutes = toMinutes(parseInt(workSum[0]), parseInt(workSum[1] / 100 * 60));
actualMinutes -= getSchoolSum(n); if (workSumMinutes === totalTimeMinutes) {
if (actualMinutes === stampMinutes) {
node.style.background = successColor; node.style.background = successColor;
sumNode.style.background = successColor; sumNode.style.background = successColor;
} else { } else {
node.style.background = errorColor; node.style.background = errorColor;
sumNode.style.background = errorColor; sumNode.style.background = errorColor;
actualNode.textContent = "stomp: " + toHoursAndMinutes(stampMinutes); actualNode.textContent = "stomp: " + toHoursAndMinutes(totalTimeMinutes);
actualNode.style.background = errorColor; actualNode.style.background = errorColor;
} }
} }
} }
function getSchoolSum(startpos) {
for (let i = startpos + 1; (i < nodes.length - 1) && (nodes[i].childNodes[columnPosBuchungstext].className != emptyCellClassName); i++) {
let activityNode = nodes[i].childNodes[columnPosActivity];
let activityText = activityNode.textContent;
if (activityText && activityText.match(/Lernende: Berufsschule/gm)) {
let schoolSum = nodes[i].childNodes[columnPosHours].getElementsByClassName("text")[0].textContent.split(".");
return toMinutes(parseInt(schoolSum[0]), parseInt(schoolSum[1] / 100 * 60));
}
}
return 0;
}
function getMinutes(first, second) { function getMinutes(first, second) {
var time_start = new Date(); var time_start = new Date();
var time_end = new Date(); var time_end = new Date();