/
Amazon Order Total.user.js
64 lines (54 loc) · 2.12 KB
/
Amazon Order Total.user.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
// ==UserScript==
// @name Amazon Order Total
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Sum up the total amazon orders
// @author Sameer711
// @license MIT
// @updateURL https://github.com/Sameer711/AmazonCaGreaseMonkeyUserScript/blob/master/Amazon%20Order%20Total.user.js
// @copyright Copyright (C) 2019, by Sameer
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @match https://www.amazon.ca/gp/your-account/order-history*
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function(jQuery) {
'use strict';
let inProgress = GM_getValue("AmazonOrderTotal_InProgress", false);
if (inProgress) {
getOrderTotal();
} else {
var getOrderTotalsButton = jQuery('<button/>',
{
text: 'Get Order Totals!',
click: startTracking,
class: 'a-button-primary'
});
jQuery(".top-controls").append(getOrderTotalsButton);
}
function startTracking() {
GM_setValue("AmazonOrderTotal",0);
GM_setValue("AmazonOrderTotal_InProgress", true);
getOrderTotal();
}
function getOrderTotal() {
let sum = GM_getValue("AmazonOrderTotal", 0);
[].forEach.call(document.getElementsByClassName('value'),function(el) {
if (el.innerText.startsWith('CDN$ ')) {
//exclude refunds.. go up to the ancestor and look for refund text in block
if (!$(el).parent().parent().parent().parent().parent().parent().parent().parent().siblings().text().includes("Refund")) {
console.log(el.innerText.substr(5));
sum+= parseFloat(el.innerText.substr(5));
}
}
})
GM_setValue("AmazonOrderTotal", sum);
console.log(sum);
if (jQuery('.a-last a').length > 0) {
jQuery('.a-last a')[0].click();
} else {
GM_setValue("AmazonOrderTotal_InProgress", false);
alert('Your total orders is: $' + sum.toFixed(2));
}
}
})(jQuery);