Skip to content

Instantly share code, notes, and snippets.

@chrisjangl
Last active December 22, 2022 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisjangl/71deae62e47a9f6ac291062e7c9a5ad1 to your computer and use it in GitHub Desktop.
Save chrisjangl/71deae62e47a9f6ac291062e7c9a5ad1 to your computer and use it in GitHub Desktop.
Scrape the FSA contributions deducted from each paycheck in a given year. Must be on the pay stubs list and have selected a year. Custom built for pay stubs in PayCom.
// get all rows that we're interested in (each represent 1 paycheck)
let rows = document.getElementById('check-listings-table').querySelectorAll('tbody tr[role="row"]');
// instantiate the array we'll use for all contributions
var contributions = [];
// loop over each row
for (var i = 0; i < rows.length; i++) {
// we never actually use this...
let row = rows[i];
// get the date of the paycheck
let paycheckDate = rows[i].querySelectorAll('td')[2].innerHTML;
// info about the paycheck is paired to a button click on the paycheck row
let expandButton = rows[i].querySelectorAll('input.ess-view');
expandButton[1].click();
// assign each paycheck category, we can loop over each as needed
let earnings = rows[i].nextElementSibling.querySelector('td.extraDetailsRow').querySelectorAll('table')[0],
taxes = rows[i].nextElementSibling.querySelector('td.extraDetailsRow').querySelectorAll('table')[1],
deductions = rows[i].nextElementSibling.querySelector('td.extraDetailsRow').querySelectorAll('table')[2],
netPay = rows[i].nextElementSibling.querySelector('td.extraDetailsRow').querySelectorAll('table')[3];
var FSA;
// there may or may not be a contribution for any given paycheck,
// so we'll need to loop over each deduction to see if it's an FSA deduction
for(item of [...deductions.querySelectorAll('tr')]) {
if ("FSA" === item.children[0].innerHTML) {
FSA = item.children[1].innerHTML;
}
}
let contribution = [paycheckDate, FSA]
contributions.push(contribution);
// close the paycheck info row on the screen
expandButton[1].click();
}
console.log(contributions)
// total the contributions
for (amount of [...contributions]) {
if (amount[1]) {
total = total + Number(amount[1].replace("$", ""))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment