-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
141 lines (120 loc) · 5.07 KB
/
index.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
(function() {
let activeVisaCenterIndex = 3
let canReset = true
let shoudlRefresh = false
function startCheckingAppointment() {
try {
const selectList = document.getElementsByTagName('mat-select')
const visaCenterSelect = selectList[0]
const visaCategorySelect = selectList[1]
const visaSubCategorySelect = selectList[2]
canReset = false
if (activeVisaCenterIndex === 7) {
activeVisaCenterIndex = 3
canReset = true
autoLogout()
return;
}
if (visaCenterSelect) {
// select visa center
visaCenterSelect.click()
const visaCenterList = document.getElementsByTagName('mat-option')
const currentVisaCenter = visaCenterList[activeVisaCenterIndex]
activeVisaCenterIndex++
currentVisaCenter.click()
let visaSubCategory = ""
let visaCategory = ""
setTimeout(() => {
// select visa category
visaCategorySelect.click()
const visaCategoryList = document.getElementsByTagName('mat-option')
visaCategory = visaCategoryList.length > 1 ? visaCategoryList[2] : visaCategoryList[0]
visaCategory.click()
}, 10000)
setTimeout(() => {
// select visa sub category
visaSubCategorySelect.click()
const visaSubCategoryList = document.getElementsByTagName('mat-option')
const visaSubCategoryArr = Array.from(visaSubCategoryList)
visaSubCategory = visaSubCategoryArr.find(visaSubCategorty => visaSubCategorty.innerText.includes('Work Permit'))
visaSubCategory.click()
}, 20000)
setTimeout(() => {
// // check if any appointments are available
const HTMLElm = document.getElementsByTagName('html')[0]
let alarmTimerId = 0
const continueBtn = document.getElementsByClassName("mat-focus-indicator btn mat-btn-lg btn-block btn-brand-orange mat-raised-button mat-button-base mat-button-disabled")[0]
if (location.href.includes("tur/en/pol/application-detail") && !HTMLElm.innerText.includes('No appointment slots are currently available') && !continueBtn) {
const audio = new Audio("https://notificationsounds.com/storage/sounds/file-sounds-1158-lovingly.mp3")
audio.play()
// alarmTimerId = setInterval(() => {
// }, 70000)
const qs = `${encodeURIComponent(currentVisaCenter.innerText)};${encodeURIComponent(visaCategory.innerText)};${encodeURIComponent(visaSubCategory.innerText)}`
fetch("http://127.0.0.1:3003/?text=" + qs, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
headers: {
'Content-Type': 'application/json',
},
}).then((data) => console.log(data)).catch(err=>console.log(err))
} else {
clearInterval(alarmTimerId)
}
canReset = true
}, 30000)
}
} catch (error) {
fetch("http://127.0.0.1:3003/?text=ERRORRRRR!!!!", {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
headers: {
'Content-Type': 'application/json',
},
}).then((data) => console.log(data)).catch(err=>console.log(err))
}
}
function autoLogin() {
let loginbtn = document.getElementsByClassName("mat-focus-indicator btn")[0]
// document.getElementsByTagName("mat-form-field")[0].focus()
// document.getElementsByTagName("mat-form-field")[1].focus()
document.getElementsByTagName("body")[0].click()
setTimeout(() => loginbtn.click(), 0)
}
function startNewBooking() {
let newBookingBtn = document.getElementsByClassName("btn mat-raised-button mat-button-base")
newBookingBtn[0].click()
}
function autoLogout() {
let logoutBtn = document.getElementsByClassName("dropdown-item bg-brand-orange")
logoutBtn[0].click()
}
setInterval(() => {
const locationHref = location.href
if (locationHref.includes("tur/en/pol/login")) {
autoLogin()
} else if (locationHref.includes("tur/en/pol/dashboard")) {
startNewBooking()
} else if (locationHref.includes("tur/en/pol/application-detail")) {
if (canReset) {
// const buttonList = document.getElementsByClassName("mat-raised-button")
// const buttonArray = Array.from(buttonList)
// const stayConnectedButton = buttonArray.find(btn => btn.innerHTML.includes("Stay Connected"))
// if (stayConnectedButton) {
// stayConnectedButton.click()
// }
startCheckingAppointment()
}
} else {
if (shoudlRefresh) {
location.href = "https://visa.vfsglobal.com/tur/en/pol/login"
return
}
shoudlRefresh = true
const qs = `${encodeURIComponent("ERROR! UNKNOWN PAGE DETECTED!")}`
fetch("http://127.0.0.1:3003/?text=" + qs, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
headers: {
'Content-Type': 'application/json',
},
}).then((data) => console.log(data)).catch(err=>console.log(err))
}
}, 30000)
})();