Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save primozcigler/578b04d3f5339ef1bf865d3e06f3ae2d to your computer and use it in GitHub Desktop.
Save primozcigler/578b04d3f5339ef1bf865d3e06f3ae2d to your computer and use it in GitHub Desktop.

Revisions

  1. primozcigler renamed this gist Mar 2, 2018. 1 changed file with 0 additions and 0 deletions.
  2. primozcigler renamed this gist Sep 28, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. primozcigler created this gist Sep 28, 2017.
    34 changes: 34 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    // Go to https://account.templatemonster.com/#/billing and scroll down to show enough BILLING HISTORY items
    // Then run the script


    {
    const dateRegex = /aug \d+, 2017/i
    // startDate = new Date('2017-8-1 00:00:00'),
    // endDate = new Date('2017-9-1 00:00:00'),
    allRows = Array.from($$( '.billing-history-operation' ));

    let rowsWithinTimeFrame = [];

    rowsWithinTimeFrame = allRows.filter(($row) => {
    let rowDate = $row.querySelector('.billing-history-operation-info__date').innerText;
    // rowDate = new Date(rowDate);

    return dateRegex.test(rowDate);
    // return daterowDate >= startDate && rowDate < endDate;
    });

    rowsWithinTimeFrame.reduce((sum, $row) => {
    let $moneyNode = $row.querySelector('.billing-history-operation-info__balance .format-currency'),
    $centsNode,
    dollars = $moneyNode.innerText;

    dollars = parseFloat(dollars.match(/[\d\.]+/)[0]);

    if ($row.classList.contains('billing-history-operation_type_refund')) { // refunds are negative
    dollars = -dollars;
    }

    return sum + dollars;
    }, 0);
    }