forked from zsxsoft/my-beancount-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd.user.js
80 lines (78 loc) · 2.51 KB
/
jd.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
// ==UserScript==
// @name JD to Beancount
// @version 0.1
// @description JD to Beancount
// @author zsx
// @match https://order.jd.com/*
// @match https://details.yiyaojd.com/*
// @match https://details.jd.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict'
const $ = document.querySelectorAll.bind(document)
const getByGoodsTotal = ($) => {
if ($('.goods-total').length > 0) {
const fp = a => a.replace(/¥|¥/, '').trim()
let p = parseFloat(fp($('.txt.count')[0].innerText))
const t = parseFloat(fp($('.goods-total .txt')[0].innerText))
let asset = ' Assets:Unknown\n'
let ecard = ''
// 礼品卡处理
const z = $('.txt.count')[0].parentNode.parentNode.children
let kk = null
for (let i = z.length - 1; i >= 0; i--) {
if (/礼品卡/.test(z[i].innerText)) {
kk = z[i]
break
}
}
if (kk !== null) {
const giftCardPaid = -(fp(kk.querySelector('.txt').innerText).replace(/ /, ''))
if (parseInt(p) === 0) {
asset = ''
p = giftCardPaid
} else {
p += giftCardPaid
}
ecard = ' Assets:Company:JD:Ecard -' + giftCardPaid.toFixed(2) + ' CNY\n'
}
// 计算
const pe = p / t
const f = Array.from($('tr[class*="product"]')).map(a => {
const q = a.querySelector.bind(a)
const t = d => q(d).innerText.trim()
return (`
${document.querySelector('[id*="datesubmit"]').value.split(' ')[0]} * "京东" "${t('.p-name')}"
Expenses:Unknown ${(fp(t('.f-price')) * a.querySelectorAll('td')[4].innerText.trim() * pe).toFixed(2)} CNY
${asset}${ecard}
`).trim()
}).join('')
console.log(f)
}
}
if ($('.td-void.order-tb').length > 0) {
setTimeout(() => {
const f = Array.from($('.order-tb tbody[id*="tb-"]')).map(a => {
const q = a.querySelector.bind(a)
const t = d => q(d).innerText
if (a.querySelectorAll('[id*="track"]').length === 1) {
return `
${t('.dealtime').split(' ')[0]} * "京东" "${t('.p-name')}"
Expenses:Unknown ${t('.amount').match(/([0-9.]+)/)[1]} CNY
Assets:Unknown
`.trim()
} else {
return `
${t('.dealtime').split(' ')[0]} * "京东" "请点击详情"
Expenses:Unknown ${t('.amount').match(/([0-9.]+)/)[1]} CNY
Assets:Unknown
`.trim()
}
}).join('\n\n')
console.log(f)
}, 5000)
}
getByGoodsTotal($)
// Your code here...
})()