-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.js
319 lines (301 loc) · 12.7 KB
/
process.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
'use strict';
let LOG_PREFIX = "SH:";
// debug function
// 0 1608759842 SH: msg
// ...
// N 1608759842+N SH: msg
function debug_log(msg) {
let current_timestamp = parseInt(new Date().getTime());
let debug_counter = parseInt(localStorage["debug-counter"]);
let header = debug_counter.toString() + ' ' +
current_timestamp.toString() + ' ' + LOG_PREFIX + ' ';
console.log(header + msg);
localStorage["debug-counter"] = debug_counter + 1;
}
//init debug structure if is first time or if more than 5 minutes elapsed
if ((typeof localStorage["timestamp"] === 'undefined') ||
(new Date().getTime() - localStorage["timestamp"]) > (5 * 60 * 1000)) {
localStorage["debug-counter"] = 0;
localStorage["user-name"] = 'false';
localStorage["confirm-btn"] = 'false';
localStorage["save-continue-btn"] = 'false';
localStorage["submit-order"] = 'false';
localStorage["invalid-user"] = 'false';
localStorage["type-cvc"] = 'false';
localStorage["error-refresh"] = 'false';
localStorage["refresh-btn"] = 'false';
localStorage["notify-me"] = 'false';
localStorage["purchased"] = 'false';
localStorage["sizes-available"] = 'false';
localStorage["enter-draw"] = 'false';
localStorage["what-is-draw"] = 'false';
localStorage["are-you-sure"] = 'false';
localStorage["an-error-occurred"] = 'false';
localStorage["got-em"] = 'false';
localStorage["entry-in"] = 'false';
localStorage["continue-shop"] = 'false';
localStorage["cookies"] = 'false';
localStorage["timestamp"] = new Date().getTime();
}
// runs every 1 second
window.setInterval(function() {
// wait page ready
if (document.readyState === 'complete') {
// get current time
let date = new Date();
let hour = date.getHours();
let minute = date.getMinutes();
let seconds = date.getSeconds();
// get all 'data-qa'
let elems = document.querySelectorAll('[data-qa]');
elems.forEach(function(elem) {
if (localStorage["user-name"] == 'false') {
// search user name
if (elem.getAttribute('data-qa') === "user-name") {
if (elem.textContent.length >= 1) {
debug_log("user-name");
// update localStorage
localStorage["user-name"] = 'true';
// go to the next iteration
return;
}
}
}
if (localStorage["confirm-btn"] == 'false') {
// search Confirm Button
if (elem.getAttribute('data-qa') === "presubmit-confirm") {
if (elem.textContent === "Confirm") {
debug_log("confirm-btn");
// update localStorage
localStorage["confirm-btn"] = 'true';
// go to the next iteration
return;
}
}
}
if (localStorage["save-continue-btn"] == 'false') {
// search save & continue button
if (elem.getAttribute('data-qa') === "save-button") {
if (elem.textContent === "Save & Continue") {
debug_log("save-continue-btn");
// update localStorage
localStorage["save-continue-btn"] = 'true';
// go to the next iteration
return;
}
}
}
if (localStorage["submit-order"] == 'false') {
// search submit order button
if (elem.getAttribute('data-qa') === "save-button") {
if (elem.textContent === "Submit Order") {
debug_log("submit-order");
// update localStorage
localStorage["submit-order"] = 'true';
// go to the next iteration
return;
}
}
}
});
// check if join/login button is available
if (localStorage["invalid-user"] == 'false') {
let joinBtn = document.getElementsByClassName("join-log-in");
// if found
Array.prototype.forEach.call(joinBtn, function(btn) {
// verify if the login name is a valid user name
if (btn.textContent === "Join/Log In") {
debug_log("invalid-user");
// update locaStorage
localStorage["invalid-user"] = 'true';
}
});
}
// check for errors
let errors = document.getElementsByClassName("text-color-error");
// if found
Array.prototype.forEach.call(errors, function(error) {
// verify if we got an error
if (error.textContent.includes("Please refresh")) {
debug_log("error-refresh");
// reload the page
window.location.reload();
// go to the next iteration
return;
}
if (localStorage["type-cvc"] == 'false') {
// search cvc field
if (error.textContent.includes("security code")) {
debug_log("type-cvc");
// update localStorage
localStorage["type-cvc"] = 'true';
// go to the next iteration
return;
}
}
});
// search notify me and purchased
let buttonCount = document.getElementsByClassName("buttoncount-1");
// if found
Array.prototype.forEach.call(buttonCount, function(btn) {
// check if notify me is still visible at 8:00
if (btn.textContent === "Notify Me") {
// check current time and reload the page
if (hour === 8 && minute === 0 && seconds <= 10) {
if (localStorage["notify-me"] == 'false') {
debug_log("notify-me");
// update localStorage
localStorage["notify-me"] = 'true';
}
// reload the page only in the first 10 seconds
window.location.reload();
// go to the next iteration
return;
}
}
// check if we found the Purchased Button
if (localStorage["purchased"] == 'false') {
if (btn.textContent === "Purchased") {
debug_log("purchased!");
// update localStorage
localStorage["purchased"] = 'true';
// go to the next iteration
return;
}
}
});
// check for table of sizes
if (localStorage["sizes-available"] == 'false') {
let sizeTable = document.getElementsByClassName("size-layout");
// if found
Array.prototype.forEach.call(sizeTable, function(table) {
// if childNodes not null, means that table of sizes is ready
for (let i = 0; i < table.childNodes.length; i++) {
// check if there is at least one size available
if (table.childNodes[i].getAttribute('data-qa') === "size-available") {
debug_log("sizes-available");
// update localStorage
localStorage["sizes-available"] = 'true';
break;
}
// TODO: reload page ??
}
// table[0].childNodes.forEach(function(node) {
// console.log(node.textContent);
// });
});
}
// what is the draw, search An error occurred message
// Got Em', entry is in
let headline_3 = document.getElementsByClassName("headline-3");
// if found
Array.prototype.forEach.call(headline_3, function(line) {
// search what is the draw
if (localStorage["what-is-draw"] == 'false') {
if (line.textContent === "WHAT IS THE DRAW?") {
debug_log("what-is-draw");
// update localStorage
localStorage["what-is-draw"] = 'true';
// go to the next iteration
return;
}
}
// search An error occurred message
if (localStorage["an-error-occurred"] == 'false') {
if (line.textContent === "An error occurred.") {
debug_log("an-error-occurred");
// update localStorage
localStorage["an-error-occurred"] = 'true';
// go to the next iteration
return;
}
}
// search Got Em'
if (localStorage["got-em"] == 'false') {
if (line.textContent === "Got 'em") {
debug_log("got-em");
// update localStorage
localStorage["got-em"] = 'true';
// go to the next iteration
return;
}
}
// search your entry is in
if (localStorage["entry-in"] == 'false') {
if (line.textContent === "Your entry is in") {
debug_log("entry-in");
// update localStorage
localStorage["entry-in"] = 'true';
// go to the next iteration
return;
}
}
});
// are you sure ?
if (localStorage["are-you-sure"] == 'false') {
let headline_1 = document.getElementsByClassName("headline-1");
// if found
Array.prototype.forEach.call(headline_1, function(line) {
// search Are You Sure Button
if (line.textContent === "ARE YOU SURE?") {
debug_log("are-you-sure");
// update localStorage
localStorage["are-you-sure"] = 'true';
// go to the next iteration
return;
}
});
}
// search buttons - Buttons Available:
// Enter Draw
// Notify Me
// Join / Log In
// Sizes
// e.t.c ...
let buttons = document.querySelectorAll("button");
buttons.forEach(function(btn) {
// search enter draw button
if (localStorage["enter-draw"] == 'false') {
if (btn.textContent.includes("Enter Draw")) {
debug_log("enter-draw");
// update localStorage
localStorage["enter-draw"] = 'true';
// go to the next iteration
return;
}
}
// search refresh button
if (localStorage["refresh-btn"] == 'false') {
if (btn.textContent === "refresh") {
debug_log("refresh-btn");
// reload the page, try only once
window.location.reload();
// update localStorage
localStorage["refresh-btn"] = 'true';
// go to the next iteration
return;
}
}
// search continue shopping
if (localStorage["continue-shop"] == 'false') {
if (btn.textContent === "Continue Shopping") {
debug_log("continue-shop");
// update localStorage
localStorage["continue-shop"] = 'true';
// go to the next iteration
return;
}
}
});
// check if OK banner cookies button is visible
if (localStorage["cookies"] == 'false') {
let cookieBtn = document.querySelector("div[data-qa='cookie-banner']").classList.contains("d-sm-h");
// if false, cookieBtn is present
if (cookieBtn === false) {
debug_log("cookies");
// update locaStorage
localStorage["cookies"] = 'true';
}
}
}
}, 1000);