-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
59 lines (54 loc) · 2.02 KB
/
script.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
const successAudio = new Audio(
'https://github.com/amoritan/dvsa-test-finder/raw/main/assets/success.mp3'
);
const warningAudio = new Audio(
'https://github.com/amoritan/dvsa-test-finder/raw/main/assets/warning.mp3'
);
const submitButton = document.getElementById('test-centres-submit');
if (submitButton) {
let beforeDateString = localStorage.getItem('testFinderBeforeDate');
if (!beforeDateString) {
beforeDateString = prompt(
'What is the latest date you want to get notified for? (DD/MM/YYYY)'
);
localStorage.setItem('testFinderBeforeDate', beforeDateString);
}
const beforeDate = new Date(beforeDateString);
if (Notification.permission !== 'granted') {
Notification.requestPermission();
}
let testCentresAvailable = [];
document.querySelectorAll('.test-centre-details-link').forEach((e) => {
const centreAvailability = e.querySelectorAll('h5')[0].textContent;
if (centreAvailability !== ' – No tests found on any date') {
const centreDateString =
centreAvailability.split(' ')[centreAvailability.split(' ').length - 1];
const centreDate = new Date(centreDateString);
if (centreDate < beforeDate) {
const centreName = e.querySelectorAll('h4')[0].textContent;
testCentresAvailable.push(`${centreName} - ${centreDateString}`);
} else {
console.log('📅 Availability found after the preferred date');
}
}
});
if (testCentresAvailable.length > 0) {
successAudio.play();
alert(
`🎉 Available test centre/s found: ${testCentresAvailable.join(', ')}`
);
} else {
console.log('😢 No available test centres were found');
window.setTimeout(
() => {
document.getElementById('test-centres-submit').click();
},
Math.floor(Math.random() * (300000 - 270000) + 270000) // Around 5 minutes
);
}
} else if (document.getElementById('main-iframe')) {
warningAudio.play();
alert('🛑 The website requires your attention');
} else {
console.log('🔍 Not on the right page yet...');
}