-
Notifications
You must be signed in to change notification settings - Fork 1
/
autocart.js
executable file
·48 lines (43 loc) · 1.16 KB
/
autocart.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
var size = "10.5";
var amount = 1;
var flag = 0;
function addToCart() {
var sizesList=document.getElementsByName("skuAndSize")[0];
function setQuantity() {
document.getElementsByName("qty")[0].selectedIndex = amount-1;
}
function setSizeValue() {
for (var i=0; i<sizesList.length; i++){
if(sizesList.options[i].text == size) {
if(sizesList.options[i].className != "exp-pdp-size-not-in-stock"){
document.getElementsByName("skuAndSize")[0].selectedIndex = i;
setQuantity();
}else{
console.log('size not availble')
return 1;
}
}
}
return 0;
}
if(sizesList != undefined) {
val = setSizeValue();
if(val == 0){
document.getElementsByClassName("add-to-cart")[0].click();
flag = 1;
}else{
console.log('size not availble, refresh page');
window.location.reload();
}
}else {
console.log('purchase not availble, refresh page');
window.location.reload();
}
}
var myChecker = setInterval(function () {
if (flag) {
clearInterval(myChecker);
} else {
addToCart();
}
}, 500);