-
Notifications
You must be signed in to change notification settings - Fork 1
/
dom.js
59 lines (57 loc) · 1.33 KB
/
dom.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
function domAction(eventType, data, options) {
switch(eventType){
case "search":
searchFK(data);
break;
case "include":
alert(data);
triggerFilter(data,true);
break;
case "exclude":
triggerFilter(data,false);
break;
case "view":
viewProduct(data);
break;
case "addcart":
addToCart();
break;
case "viewcart":
viewCart();
break;
}
function searchFK(data){
var searchBarInputs = jQuery(".search-bar input");
var searchBox = searchBarInputs[0],
submitButton = searchBarInputs[3];
searchBox.value = data;
if(!submitButton)
return;
jQuery(submitButton).trigger("click");
}
function triggerFilter(data,triggerOption){
var li = getFilters(data);
if(!li)
return;
if(!li.getElementsByTagName('input')[0].checked && triggerOption)
li.getElementsByTagName('a')[0].click();
if(li.getElementsByTagName('input')[0].checked && !triggerOption)
li.getElementsByTagName('a')[0].click();
}
function viewProduct(data){
var div = getResults(data);
if(!div)
return;
console.log(div);
div.getElementsByTagName('a')[0].click();
}
function addToCart(){
jQuery(".btn-buy-now")[0].click();
location.reload();
}
function viewCart(){
// jQuery('.btn-cart')[0].trigger("click");
window.location.href = "https://www.flipkart.com/viewcart";
// location.reload('');
}
}