-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathpass-fur-alle.js
222 lines (197 loc) · 8.66 KB
/
pass-fur-alle.js
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
// ==UserScript==
// @name Pass für alle
// @namespace https://passfuralle.se
// @version 2.17
// @description Ett snabbt och enkelt sätt att boka passtid
// @author Jonk
// @match https://*.nemoq.se/Booking/Booking/*
// @grant none
// @require https://code.jquery.com/jquery-3.6.0.min.js#sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=
// @require https://cdnjs.cloudflare.com/ajax/libs/ion-sound/3.0.7/js/ion.sound.min.js
// ==/UserScript==
(function() {
var jQuery = window.jQuery;
var ion = window.ion;
// Constants
log('Set constants');
var dateFrom = today();
var dateTo = '2022-12-24';
var autoConfirm = true;
var acceptOffice = '';
var datePickerElem = jQuery('#datepicker');
if (!localStorage.getItem('TimeSearch')) {
log('Set start date');
datePickerElem.val(dateFrom);
}
jQuery('input[name="TimeSearchButton"]').on('click', function () {
log('Start time search');
localStorage.setItem('TimeSearch', 'TimeSearchButton');
localStorage.removeItem('responseText');
});
jQuery('input[name="TimeSearchFirstAvailableButton"]').on('click', function () {
log('Start time search first available');
localStorage.setItem('TimeSearch', 'TimeSearchFirstAvailableButton');
localStorage.removeItem('responseText');
});
jQuery('a[href*="/Booking/Booking/Previous/skane?id="]').on('click', function() {
log('Clear time search');
localStorage.removeItem('TimeSearch');
localStorage.removeItem('responseText');
});
jQuery('body').on('click', 'a.cancel-search', function() {
log('Cancel search');
jQuery('html, body').css('overflow', 'visible');
localStorage.removeItem('TimeSearch');
localStorage.removeItem('responseText');
location.reload();
});
setButtonTexts();
jQuery("#SectionId").change(function() {
setButtonTexts();
});
// Find a time
if (jQuery('.controls .btn.btn-primary[name="TimeSearchButton"]').length || jQuery('.controls .btn.btn-primary[name="TimeSearchFirstAvailableButton"]').length) {
log('Time search view');
var datePickerVal = datePickerElem.val();
if (Date.parse(datePickerVal) < Date.parse(dateFrom)) {
log('Start later than today');
datePickerElem.val(dateFrom);
}
if (localStorage.getItem('TimeSearch')) {
log('Start time search');
loader();
captcha();
if (Date.parse(datePickerVal) > Date.parse(dateTo) || (localStorage.getItem('TimeSearch') == 'TimeSearchButton' && Date.parse(datePickerVal) < Date.parse(dateFrom))) {
log('Start over time search');
datePickerElem.val(dateFrom);
setTimeout(function () {
jQuery('input[name="' + localStorage.getItem('TimeSearch') + '"]').click();
}, timeSearchTimeout());
} else {
log('Check for slot');
var availableTimeSlots = jQuery('.pointer.timecell.text-center[data-function="timeTableCell"][aria-label!="Bokad"]');
// Filter accepted passport offices
if(acceptOffice && acceptOffice.length) {
availableTimeSlots = availableTimeSlots.filter(function() {
var office = jQuery(this).closest(".timetable-cells").attr("headers");
return acceptOffice.split(",").some(function(acceptedOffice) {
return office.includes(acceptedOffice)
});
})
}
if (availableTimeSlots.length) {
log('Time found');
availableTimeSlots.first().click();
var timeSelectionText;
if (jQuery.trim(jQuery('#timeSelectionText').text()).length) {
timeSelectionText = jQuery('#timeSelectionText').text();
} else {
timeSelectionText = availableTimeSlots.first().data('fromdatetime');
}
var responseText = jQuery.trim(jQuery('#selectionText').text() + ' ' + jQuery('#sectionSelectionText').text() + ' ' + timeSelectionText);
localStorage.setItem('responseText', responseText);
if (autoConfirm || confirm(responseText)) {
log('Auto confirm');
jQuery('#booking-next').click();
}
} else {
log('No time found');
setTimeout(function () {
log('Check next');
if (jQuery('#nextweek').length) {
log('Check next week');
jQuery('#nextweek').attr('name','TimeSearchButton');
jQuery('#nextweek').click();
} else if (jQuery('.btn.btn-link.pull-right').attr('name','KeyTimeSearchNextDayButton').length) {
log('Check next day');
jQuery('.btn.btn-link.pull-right').attr('name','KeyTimeSearchNextDayButton').click();
}
}, timeSearchTimeout());
}
}
}
}
// Time found
if (jQuery('.breadcrumb li').length == 6) {
log('Book time view');
jQuery('.breadcrumb').after('<h2 style="text-align:center;padding:20px;">' + localStorage.getItem('responseText') + '</h2>');
localStorage.removeItem('TimeSearch');
localStorage.removeItem('responseText');
playSound('bell_ring');
}
function log(log) {
console.log(log);
}
function timeSearchTimeout() {
log('Set timeout');
var timeout = 1000;
/*
if (localStorage.getItem('TimeSearch') == 'TimeSearchFirstAvailableButton') {
log('Long timeout');
timeout = 15000;
} else {
log('Normal timeout');
}
*/
return timeout;
}
function today() {
var today = new Date();
return today.toISOString().slice(0,10);
}
function setButtonTexts() {
log('Set button texts');
jQuery('input[name="TimeSearchFirstAvailableButton"]').val('Första lediga tid innan ' + dateTo);
if (jQuery("#SectionId option:selected").val() == 0) {
jQuery('input[name="TimeSearchButton"]').val('Sök tid mellan ' + dateFrom + ' och ' + dateTo);
jQuery('input[name="TimeSearchButton"]').css('display', '');
} else {
jQuery('input[name="TimeSearchButton"]').val('Funkar inte än');
jQuery('input[name="TimeSearchButton"]').css('display', 'none');
}
}
function playSound(sound) {
// http://ionden.com/a/plugins/ion.sound/en.html
ion.sound({
sounds: [
{name: sound}
],
// main config
path: "https://cdnjs.cloudflare.com/ajax/libs/ion-sound/3.0.7/sounds/",
preload: true,
multiplay: true,
volume: 0.9
});
// play sound
ion.sound.play(sound);
}
function loader() {
if (!jQuery('.loading').length) {
jQuery('html, body').css('overflow', 'hidden');
jQuery('body').append('<div class="loading" style="display: flex; width: 100vw; height: 100vh; position: absolute; left: 0; top: 0; justify-content: center; align-items: center;z-index: 999; background: rgba(255,255,255,.6);"><div style="background: #eee; padding: 20px; border-radius: 20px; width: 200px; height: 200px; display: flex; justify-content: center; align-items: center; flex-direction: column; z-index: 999;"><div>Söker efter tid</div><div class="loader-animation">.</div><a href="#" class="cancel-search">Avbryt</a></div></div>');
loaderAnimation();
}
}
function captcha() {
if (jQuery('.mtcaptcha').length) {
playSound('light_bulb_breaking');
localStorage.removeItem('TimeSearch');
localStorage.removeItem('responseText');
setTimeout(function () {
location.href = location.href;
}, 1000);
}
}
function loaderAnimation() {
jQuery('.loader-animation').html('.');
setTimeout(function () {
jQuery('.loader-animation').html('..');
}, 250);
setTimeout(function () {
jQuery('.loader-animation').html('...');
}, 500);
setTimeout(function () {
loaderAnimation();
}, 750);
}
})();