Last active
May 26, 2020 16:09
-
-
Save svapreddy/b139179a859b34c95c09a6650f2e2e12 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// STEPS: | |
// Preferred Browser - Google Chrome Latest | |
// 1. Open ADP Paychecks Page. You will see the paychecks displayed with ID and date range. | |
// 2. Open Developer Tools by Mouse Right Click -> Inspect Element. Now, Select Console Tab (Usually Second Tab) | |
// 3. Paste the Below code and press Enter. | |
// 4. Once all the paychecks are downloaded to your Downloads Folder, goto next page of Paychecks and paste the code again in the Console. | |
function downloadURI(uri, name) { | |
var link = document.createElement("a"); | |
link.download = name; | |
link.href = uri; | |
link.click(); | |
} | |
(async () => { | |
let arrayBufferToBase64 = (buffer) => { | |
let binary = ''; | |
let bytes = [].slice.call(new Uint8Array(buffer)); | |
bytes.forEach((b) => binary += String.fromCharCode(b)); | |
return btoa(binary); | |
}; | |
let downloadPDF = async (url) => { | |
let req = await fetch(url); | |
const buffer = await req.arrayBuffer(); | |
console.log(buffer); | |
let base64Flag = `data:application/pdf;base64,`; | |
let pdfStr = arrayBufferToBase64(buffer); | |
return base64Flag + pdfStr; | |
}; | |
let elements = document.querySelectorAll('[href^="viewpaycheck"]'); | |
elements = Array.prototype.slice.call(elements, 0); | |
elements = elements.map((element) => { | |
const columns = element.closest('tr').querySelectorAll('td'); | |
const name = `${columns[0].textContent}-${columns[2].textContent}`; | |
return { | |
name, | |
url: element.getAttribute('href') | |
} | |
}); | |
for (const info of elements) { | |
const resp = await downloadPDF(info.url); | |
downloadURI(resp, info.name); | |
} | |
alert('All done in this page. Go to next records and run the script again'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment