-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
72 lines (57 loc) · 1.89 KB
/
main.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
// This is the content script
console.log('Loaded')
const texts = $('.info-item dd .txt-tobe-copied').toArray().map((e) => {
return $(e).text()
})
const name = texts[3];
const address1 = texts[4];
const address2 = "";
const zip = texts[5];
const city = texts[6];
const country = texts[7];
let all_articles = []
// const articles = big_table.find('tbody tr').get().filter((_, i) => i > 0).map((e) => {
// return $(e).find('td').get().filter((e, i) => i !== 2 && i < 5).map(e => $.trim($(e).text()));
// });
const articles = $('.items-row').toArray().map((e) => {
return [
parseInt($(e).find('.quantity').text()),
$(e).find('.item-itemID').text().replace('(', '').replace(')', ''),
$(e).find('.item-title').text(),
$(e).find('.soldFor').text().replace('€', '')
]
})
let shipping = parseFloat($('.totals-summary > dl > div:nth-child(2) > dd').text().replace(' €', '').replace(',', '.'))
console.log(articles, shipping);
console.log(name, address1, address2, zip, city, country);
all_events = $('.purchase-details .info-item dd').toArray()
let buyDay = $(all_events[3]).text()
let payDay = $(all_events[4]).text().split(' ').slice(0, 3).join(" ")
let reduction = parseFloat($('.totals-summary > dl > div:nth-child(3) > dd').text().replace(' €', '').replace(',', '.'))
const changeDate = d => {
const parts = d.split(' ')
parts[1] += '.'
return parts.join(" ")
}
console.log(buyDay, payDay, reduction)
moment.locale('de');
buyDay = moment(changeDate(buyDay), "ll");
payDay = moment(changeDate(payDay), "ll");
let buyDateString = buyDay.format('LL');
let invoiceFileDate = buyDay.format('YYYYMMDD');
let payDateString = payDay.format('LL');
let obj = {
name,
address1,
address2,
zip,
city,
country,
articles,
buyDateString,
shipping,
payDateString,
invoiceFileDate,
reduction
};
chrome.storage.sync.set(obj)