Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var transactions = $('center + .global_a_hover')
- .innerText
- .split('\n')
- .map(s => s.trim())
- .filter(Boolean);
- var regexProfit = /(?<resNumber>\d+) шт. (?<resType>.+) за (?<goldSum>\d+) золота/gm;
- var resources180 = new Set([
- 'Древесина', 'Руда'
- ])
- var profits = transactions.reduce((acc, t) => {
- const matched = regexProfit.exec(t);
- if (matched) {
- const resPrice = resources180.has(matched.groups.resType)
- ? 180
- : 360;
- const resNumber = Number(matched.groups.resNumber);
- const resSum = resPrice * resNumber;
- const transactionProfit = resSum - Number(matched.groups.goldSum);
- const profitPerRes = transactionProfit / resNumber;
- acc.push({
- transactionProfit,
- resType: matched.groups.resType,
- resNumber,
- resSum,
- profitPerRes,
- });
- }
- return acc;
- }, []);
- var totalProfit = profits.reduce((acc, p) => acc + p.transactionProfit, 0);
- console.log('profits: ', totalProfit, profits);
Advertisement
Add Comment
Please, Sign In to add comment