added stomp file
This commit is contained in:
		
						commit
						229b64953d
					
				|  | @ -0,0 +1,117 @@ | ||||||
|  | // ==UserScript==
 | ||||||
|  | // @name         stomp
 | ||||||
|  | // @namespace    https://github.com/dmtbz
 | ||||||
|  | // @source       https://github.com/dmtbz/stomp
 | ||||||
|  | // @version      1.4
 | ||||||
|  | // @description  try to take over the world!
 | ||||||
|  | // @author       You
 | ||||||
|  | // @match        https://services.bsi-software.com/bsicrm/*
 | ||||||
|  | // @updateURL    https://raw.githubusercontent.com/dmtbz/stomp/main/stomp.js
 | ||||||
|  | // @downloadURL  https://raw.githubusercontent.com/dmtbz/stomp/main/stomp.js
 | ||||||
|  | // @grant        none
 | ||||||
|  | // ==/UserScript==
 | ||||||
|  | 
 | ||||||
|  | document.addEventListener('keyup', doc_keyUp, false); | ||||||
|  | 
 | ||||||
|  | const successColor = "#1c9c31" | ||||||
|  | const errorColor = "#fa3737" | ||||||
|  | 
 | ||||||
|  | function doc_keyUp(e) { | ||||||
|  |   if (e.keyCode == 145) { | ||||||
|  |     if (!document.querySelector("div.menubar-box.left > div:nth-child(3) > span.content.text").textContent.match("Neue Arbeit")) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |     var headers = document.getElementsByClassName("table-header-item-text"); | ||||||
|  |     var columnPosBuchungstext; | ||||||
|  |     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++) { | ||||||
|  |       if (headers[i]) { | ||||||
|  |         if (headers[i].textContent.match(/Buchungstext/gm)) { | ||||||
|  |           columnPosBuchungstext = i; | ||||||
|  |         } else if (headers[i].textContent.match(/Dauer \[h]/gm)) { | ||||||
|  |           columnPosHours = i; | ||||||
|  |         } else if (headers[i].textContent.match(/Aktivität/gm)) { | ||||||
|  |           columnPosActivity = i; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     var startpos; | ||||||
|  |     var nodes = document.getElementsByClassName("table-row leaf first")[0].parentNode.children; | ||||||
|  |     for (let i = 0; i < nodes.length; i++) { | ||||||
|  |       if (nodes[i].className.match(/table-row leaf (?:selected select-single )?first/g)) { | ||||||
|  |         startpos = i; | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // 0800-1200/1245-1700[]
 | ||||||
|  |     for (let i = startpos; i < nodes.length - 1; i++) { | ||||||
|  |       let node = nodes[i].childNodes[columnPosBuchungstext]; | ||||||
|  |       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)) { | ||||||
|  |         let morning = getMinutes(text.substring(0, 4), text.substring(5, 9)); | ||||||
|  |         let afternoon = getMinutes(text.substring(10, 14), text.substring(15, 19)); | ||||||
|  |         let stampMinutes = morning + afternoon + parseInt(text.match(/\[([-]?[0-9]+)\]/)[1]); | ||||||
|  |         let n = i; | ||||||
|  |         while (nodes[n].childNodes[columnPosBuchungstext].className != emptyCellClassName) { | ||||||
|  |           n--; | ||||||
|  |         } | ||||||
|  |         let sumNode = nodes[n].childNodes[columnPosHours]; | ||||||
|  |         let actualNode = nodes[n].childNodes[columnPosBuchungstext]; | ||||||
|  |         let workSum = nodes[n].childNodes[columnPosHours].getElementsByClassName("text")[0].textContent.split("."); | ||||||
|  |         let actualMinutes = toMinutes(parseInt(workSum[0]), parseInt(workSum[1] / 100 * 60)); | ||||||
|  |         actualMinutes -= getSchoolSum(n); | ||||||
|  |         if (actualMinutes === stampMinutes) { | ||||||
|  |           node.style.background = successColor; | ||||||
|  |           sumNode.style.background = successColor; | ||||||
|  |         } else { | ||||||
|  |           node.style.background = errorColor; | ||||||
|  |           sumNode.style.background = errorColor; | ||||||
|  |           actualNode.textContent = "stomp: " + toHoursAndMinutes(stampMinutes); | ||||||
|  |           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) { | ||||||
|  |       var time_start = new Date(); | ||||||
|  |       var time_end = new Date(); | ||||||
|  |       var value_start = slice(first, 2); | ||||||
|  |       var value_end = slice(second, 2); | ||||||
|  | 
 | ||||||
|  |       time_start.setHours(value_start[0], value_start[1], 0, 0); | ||||||
|  |       time_end.setHours(value_end[0], value_end[1], 0, 0); | ||||||
|  |       return (time_end - time_start) / 1000 / 60 || 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     function slice(str, index) { | ||||||
|  |       return [str.slice(0, index), str.slice(index)]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     function toHoursAndMinutes(totalMinutes) { | ||||||
|  |       const hours = Math.floor(totalMinutes / 60); | ||||||
|  |       const minutes = totalMinutes % 60 / 60 * 100; | ||||||
|  |       return hours + "." + minutes; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     function toMinutes(hours, minutes) { | ||||||
|  |       return hours * 60 + minutes; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue