Created
February 14, 2020 02:52
-
-
Save mindevolution/7c04f798c93698182ae4932716f50f94 to your computer and use it in GitHub Desktop.
Calculate data for browser table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let calculateEachMonth = () => { | |
const data = {}; | |
const dataYear = {}; | |
document.querySelectorAll('#list > div > table > tbody > tr').forEach(row => { | |
const dateCell = row.querySelector('td:nth-child(1)').innerHTML; | |
const money = Number(row.querySelector('td:nth-child(2)').innerHTML.replace(/[^0-9\.]/g, '')); | |
const yearMonth = 'T' + dateCell.replace(/月.*/g, '').replace(/ /, ''); | |
const year = 'T' + dateCell.replace(/ \d*月.*/g, ''); | |
if (data[yearMonth]) { | |
data[yearMonth] += money; | |
} else { | |
data[yearMonth] = money; | |
} | |
if (dataYear[year]) { | |
dataYear[year] += money; | |
} else { | |
dataYear[year] = money; | |
} | |
}); | |
console.log('每月提现', data); | |
console.log('每年提现', dataYear); | |
}; | |
calculateEachMonth(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment