-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheBay - Display Totals with Shipping.user.js
125 lines (107 loc) · 5.17 KB
/
eBay - Display Totals with Shipping.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
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
// ==UserScript==
// @name eBay - Display Totals with Shipping
// @namespace http://www.toraboka.com/~mrudat
// @description Computes and displays the total price with shipping added.
// @include http://*.ebay.tld/*sch/*
// @include http://*.ebay.tld/*i.html?*
// @include http://*.ebay.tld/itm/*
// @version 0.0.5
// ==/UserScript==
/* jshint esnext: true */
process();
function process() {
var currency = '$';
var price = /\$([\d\,]*\.\d\d)/; // regexp to test for currency
var tld = location.host.split('.').reverse()[0];
switch (tld) {
case 'uk':
currency = '£';
price = /£([\d\,]*.\d\d)/;
break;
}
var itemPage = /^\/itm\//.test(location.pathname);
if (itemPage) {
var buyItNowPrice = -1;
var shippingPrice = -1;
//TODO display table of total price for 1 .. min(10,available) of item (presuming shipping cost differs)
//FIXME only possible if we can work out conversion rate for extra shipping; possibly not worthwhile?
//var priceTableTarget = document.querySelector('div.quantity').parentNode;
//var shippingTable = document.querySelector('table.sh-tbl');
var priceSummary = document.querySelector('span#prcIsum');
var priceSummaryConverted = document.querySelector('span#convbinPrice');
var priceSummaryConvertedContainer = document.querySelector('span#prcIsumConv');
var priceSummaryText = null;
if (priceSummaryConverted !== null) {
priceSummaryText = priceSummaryConverted.textContent;
priceSummaryConverted.parentNode;
} else if (priceSummary !== null) {
priceSummaryText = priceSummary.textContent;
}
var priceSummaryCurrency = "";
if (priceSummaryText !== null) {
priceSummaryCurrency = priceSummaryText.substring(0, priceSummaryText.indexOf(currency) + 1);
buyItNowPrice = priceSummaryText.match(price)[1].replace(',','');
}
var shippingCost = document.querySelector('span#fshippingCost');
var shippingCostConverted = document.querySelector('span#convetedPriceId');
var shippingCostText = null;
if (shippingCostConverted !== null) {
shippingCostText = shippingCostConverted.textContent;
} else if (shippingCost != null) {
shippingCostText = shippingCost.textContent;
}
if (shippingCostText !== null) {
if (/Free/.test (shippingCostText) || (/Digital delivery/.test(shippingCostText))) {
shippingPrice = 0;
} else if (/Not specified/.test(shippingCostText)) {
shippingPrice = '?';
} else if (price.test(shippingCostText)){
shippingPrice = shippingCostText.match(price)[1].replace(',','');
}
}
if (buyItNowPrice != -1 && shippingPrice != -1) {
var buyItNowTotal = "?";
if (!isNaN(buyItNowPrice) && !isNaN(shippingPrice)){
buyItNowTotal = (parseFloat(buyItNowPrice) + parseFloat(shippingPrice)).toFixed(2);
}
if (priceSummaryConverted !== null){
priceSummaryConverted.parentNode.parentNode.removeChild(priceSummaryConverted.parentNode);
}
priceSummary.innerHTML = priceSummaryCurrency + buyItNowTotal;
}
} else {
Array.prototype.forEach.call(document.querySelectorAll('li[listingid]'),rowElement => {
var buyItNowPrice = -1;
var shippingPrice = -1;
var lvprices = rowElement.querySelector('ul.lvprices');
// TODO what is this for?
Array.prototype.forEach.call(lvprices.querySelectorAll('div.cmpat'),i => i.parentNode.removeChild(i));
var shipping = lvprices.querySelector('span.fee');
if (shipping !== null) {
var tc = shipping.textContent;
if (/Free/.test (tc) || (/Digital delivery/.test(tc))) {
shippingPrice = 0;
} else if (/Not specified/.test(tc)) {
shippingPrice = '?';
} else if (price.test(tc)){
shippingPrice = tc.match(price)[1].replace(',','');
}
}
var buyItNow = lvprices.querySelector('li.lvprice span.bold') || lvprices.querySelector('li.lvprice');
var priceSummaryCurrency = "";
if (buyItNow !== null) {
var tc = buyItNow.textContent;
priceSummaryCurrency = tc.substring(0, tc.indexOf(currency) + 1);
buyItNowPrice = tc.match(price)[1].replace(',','');
}
if (buyItNowPrice != -1 && shippingPrice != -1) {
var buyItNowTotal = "?";
if (!isNaN(buyItNowPrice) && !isNaN(shippingPrice)){
buyItNowTotal = (parseFloat(buyItNowPrice) + parseFloat(shippingPrice)).toFixed(2);
}
buyItNow.innerHTML = buyItNow.innerHTML.substring(0, buyItNow.innerHTML.indexOf('</b>') + 4) + priceSummaryCurrency + buyItNowTotal;
shipping.innerHTML = shipping.innerHTML.replace('+','including ');
}
});
}
}