-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblueant.user.js
More file actions
236 lines (220 loc) · 9.7 KB
/
blueant.user.js
File metadata and controls
236 lines (220 loc) · 9.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// ==UserScript==
// @name Fuck Blueant
// @namespace http://tampermonkey.net/
// @version 0.5
// @description Nobody should be forced to waste his time like this. Refresh on presence page for the script to work.
// @author localh0rzd
// @updateURL https://github.com/localh0rzd/Userscripts/raw/master/blueant.user.js
// @match https://blueant.optimal-systems.org/blueant/*
// @grant none
// ==/UserScript==
const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
let waitForPresencePageTimeout;
let attempt = 0
let aborted = false
let iframeWindow, iframeDocument
let fromInput, toInput, breakInput, durationInput;
if (window.top === window.self) {
setTimeout(() => {
iframeWindow = document.querySelector("iframe").contentWindow
iframeDocument = document.querySelector("iframe").contentDocument
waitForPresencePage()
}, 500)
}
function waitForPresencePage() {
clearTimeout(waitForPresencePageTimeout)
console.info(iframeDocument.querySelector("div#presenceContainer"))
if (iframeDocument && iframeDocument.querySelector("div#presenceContainer")) {
stuff()
} else {
iframeDocument.querySelector("div#presenceContainer")
console.info("Waiting for presence page")
if (attempt < 5) {
waitForPresencePageTimeout = setTimeout(waitForPresencePage, 1000)
attempt += 1
}
}
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
}
function pickTimes(halfDay) {
const arrival = new Date(`1970-01-01T10:00:00`)
const modifier = new Date(Math.floor(Math.random() * 45) * 60000)
const toAdd = +new Date() % 2 == 0 ? +modifier : +modifier * -1
const arrivalFinal = new Date(+arrival + toAdd)
const departure = new Date(+arrivalFinal + (halfDay ? 15300000 : 30600000))
const departureFinal = new Date(+departure + (getRandomInt(-10, 15) * 60000))
const workTime = new Date(+departureFinal - +arrivalFinal - 1800000)
return {
arrival: `${arrivalFinal.getHours().toString().padStart(2, "0")}:${arrivalFinal.getMinutes().toString().padStart(2, "0")}`,
departure: `${departureFinal.getHours().toString().padStart(2, "0")}:${departureFinal.getMinutes().toString().padStart(2, "0")}`,
time: `${(workTime.getHours() - 1).toString().padStart(2, "0")}:${workTime.getMinutes().toString().padStart(2, "0")}`
}
}
function stuff() {
const bangnav = document.querySelector("ul.nano-content")//document.querySelector("div[data-qs-name='nav'] ul")
const startButton = document.createElement("button")
const goToBeginningButton = document.createElement("button")
const stopButton = document.createElement("button")
const eingabeInput = iframeDocument.querySelector("td.eingabe")
const callback = iframeWindow.ajaxEventCallbackWithWaitLogo
let fromInputValue, toInputValue, breakInputValue;
const eventCallbackWithDebounce = (a, b, c, d) => {
// We need to reset the values, because some funky scripting in the background resets them unconditionally
if (fromInputValue || fromInputValue == "") {
fromInput.value = fromInputValue
}
if (toInputValue || toInputValue == "") {
toInput.value = toInputValue
}
if (breakInputValue || breakInputValue == "") {
breakInput.value = breakInputValue
}
callback(a, b, c, d)
}
iframeWindow.ajaxEventCallbackWithWaitLogo = eventCallbackWithDebounce
startButton.innerHTML = "Autocomplete"
goToBeginningButton.innerHTML = "Jump to October 2017"
stopButton.innerHTML = "HALT STOPP"
async function processWeek(weekDate, dateData) {
if(aborted) {
return
}
if (weekDate) {
iframeWindow.ajax_showWeekWt(+weekDate, '1', '1337')
await wait(500)
} else if (dateData) {
iframeWindow.ajax_showWeekWt(dateData, '1', '1337')
await wait(500)
}
const DATE_TIME_WAIT = 800
const relevantMonthDays = iframeDocument.querySelectorAll("td.cm_day:not(.cm_weekend):not(.cm_outside):not(.genehmigt):not(.genehmigtcalendarcurrent):not(.cm_kw_finished):not(.cm_weekend_outside):not(.worktimebg)")
for (const day of relevantMonthDays) {
const buttons = iframeDocument.querySelectorAll("button")
let link = day.querySelector("a").href
let dateData = link.match(/'(.*?)'/gi).map(x => x.replace(/'/g, ""))
if (dateData[0] > +new Date()) {
console.info("for(): Won't add attendance for the future, exiting")
return;
}
const evt = new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: iframeWindow
});
iframeWindow.ajax_showWeekWt(dateData[0], dateData[1], dateData[2])
iframeWindow.ajax_setDefaultWorktimeStartValue(dateData[3], dateData[4], dateData[5])
await wait(800)
fromInput = iframeDocument.querySelector("input[name=from_time]")
toInput = iframeDocument.querySelector("input[name=to_time]")
breakInput = iframeDocument.querySelector("input[name=break]")
durationInput = iframeDocument.querySelector("input[name=dauer]")
const isHalfDayOff = /halfDay/gi.test(day.classList.toString());
const times = pickTimes(isHalfDayOff)
fromInput.value = times.arrival
fromInputValue = times.arrival
fromInput.focus()
await wait(DATE_TIME_WAIT)
try {
iframeDocument.querySelector("button.ui-datepicker-close").click()
} catch (e) {}
await wait(DATE_TIME_WAIT)
toInput.value = times.departure
toInputValue = times.departure
toInput.focus()
await wait(DATE_TIME_WAIT)
try {
iframeDocument.querySelector("button.ui-datepicker-close").click()
} catch (e) {}
await wait(DATE_TIME_WAIT)
breakInput.value = "00:30"
breakInputValue = "00:30"
breakInput.focus()
await wait(DATE_TIME_WAIT)
try {
iframeDocument.querySelector("button.ui-datepicker-close").click()
} catch (e) {}
await wait(DATE_TIME_WAIT)
//debugger
fromInput.dispatchEvent(new Event("change"))
toInput.dispatchEvent(new Event("change"))
breakInput.dispatchEvent(new Event("change"))
await wait(100)
if (aborted) {
return
}
buttons[0].click()
await wait(750)
//iframeDocument.querySelectorAll("div.listbox-wrapper")[1].click()
iframeDocument.querySelectorAll("#default input.ba.baInput")[1].click()
//const dropdownElements = iframeDocument.querySelectorAll("li.list-option.active")
//dropdownElements[dropdownElements.length - 1].click()
const dropdownList = iframeDocument.querySelectorAll("div[id^=bangListboxgc]")[1]
dropdownList.click()
await wait(500)
const dropdownEntries = iframeDocument.querySelectorAll("li.level-1 > span")
const dropdownEntry = dropdownEntries[dropdownEntries.length - 1]
dropdownEntry.focus()
dropdownEntry.click()
await wait(500)
durationInput.value = times.time
durationInput.dispatchEvent(new Event("change"))
if (aborted) {
return
}
buttons[1].click()
await wait(1000)
fromInputValue = null
toInputValue = null
breakInputValue = null
}
iframeDocument.querySelector("td.cm_right_buttons > div > div > a").click()
await wait(1000)
processWeek()
/*
if (!weekDate || relevantMonthDays.length == 0) {
const outsideDays = iframeDocument.querySelectorAll("td.cm_outside > div:not(.hint) > a, td.cm_weekend_outside > div:not(.hint) > a")
const lastOutsideDay = outsideDays[outsideDays.length - 1]
let dateData = lastOutsideDay.href.match(/'(.*?)'/gi).map(x => x.replace(/'/g, ""))
processWeek(null, dateData[0])
} else {
const lastYear = weekDate.getFullYear()
const lastMonth = weekDate.getMonth() + 1
if (+new Date() < +weekDate) {
console.info("Won't add attendance for the future, exiting")
} else if (lastMonth == 12) {
processWeek(new Date(`${+lastYear + 1}-01-01T00:00:00`))
} else {
processWeek(new Date(`${lastYear}-${(+lastMonth + 1).toString().padStart(2, "0")}-01T00:00:00`))
}
}
*/
}
startButton.addEventListener("click", e => {
aborted = false
processWeek()
})
goToBeginningButton.addEventListener("click", e => {
iframeWindow.ajax_showWeekWt(+new Date(`2017-10-01T00:00:00`), '1', '1337')
})
stopButton.addEventListener("click", e => {
aborted = true
setTimeout(() => {
fromInputValue = null
toInputValue = null
breakInputValue = null
}, 2500)
})
const li1 = document.createElement("li")
const li2 = document.createElement("li")
const li3 = document.createElement("li")
li1.appendChild(startButton)
li2.appendChild(goToBeginningButton)
li3.appendChild(stopButton)
bangnav.appendChild(li1)
bangnav.appendChild(li2)
bangnav.appendChild(li3)
}