Skip to content

Instantly share code, notes, and snippets.

@mindevolution
Created February 14, 2020 02:52
Show Gist options
  • Save mindevolution/7c04f798c93698182ae4932716f50f94 to your computer and use it in GitHub Desktop.
Save mindevolution/7c04f798c93698182ae4932716f50f94 to your computer and use it in GitHub Desktop.
Calculate data for browser table
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