-
Notifications
You must be signed in to change notification settings - Fork 0
/
mylazadatotal_bookmarklet.js
100 lines (65 loc) · 2.6 KB
/
mylazadatotal_bookmarklet.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
if (window.location.href.includes("my.lazada.com.my/customer/order/index/")) {
var gg = document.getElementById("mylazadatotal");
if (gg != null) {
gg.remove();
}
var x = document.createElement("div");
x.style.background = "white";
x.style.textDecoration.fontcolor = "black";
x.style.padding = "20px";
x.id = "mylazadatotal";
var k = document.getElementsByClassName("lzd-playground-right")[0];
k.insertBefore(x, k.firstElementChild.nextSibling);
var m = document.getElementById("mylazadatotal");
var title = document.createElement("h2");
title.innerText = "My Lazada Grand Total";
title.style.marginBottom = "20px";
m.appendChild(title);
document.querySelector("input[name=select-faker]").click();
document.querySelector("li[value='6']").click();
try {
document.getElementsByClassName("next-pagination-list")[0].firstChild.click();
} catch(err){}
setTimeout(function(){
var totalItem = parseInt(document.getElementsByClassName("next-pagination-display")[0].innerText.split("/")[1]);
var itemHeader = document.querySelectorAll(".shop-header");
var grandTotal = 0;
var loopCount = 0;
function countTotal(){
for(var i = 0; i < itemHeader.length; i++){
if(itemHeader[i].innerHTML.includes("Delivered")){
var getSibling = itemHeader[i].nextElementSibling;
var itemTitle = getSibling.querySelector(".item-title").innerHTML;
var itemPricePerUnit = parseFloat(getSibling.querySelector(".item-price").innerHTML.replace("RM","").replace(",",""));
var quantity = parseInt(getSibling.querySelector(".item-quantity > span > span").nextSibling.innerText);
var total = itemPricePerUnit * quantity;
grandTotal += total;
var output = "[ RM " + total + " ] -- " + itemTitle + " (" + quantity + ")";
console.log(output);
var item = document.createElement("p");
item.innerText = output;
m.appendChild(item);
}
}
try{
document.getElementsByClassName("next-pagination-list")[0].querySelector(".current").nextElementSibling.click();
} catch(err){}
setTimeout(function(){
if(loopCount < totalItem){
countTotal();
} else {
var gTotal = "Grand Total : RM " + Math.round(grandTotal * 100) / 100;
console.log(gTotal);
var item = document.createElement("p");
item.innerText = gTotal;
item.style.marginTop = "20px";
m.appendChild(item);
}
}, 3000);
loopCount++;
}
countTotal();
}, 2000);
} else {
window.location.href = "https://my.lazada.com.my/customer/order/index/";
}