Last active
October 31, 2022 09:55
-
-
Save GiorgioAresu/16c526ceef14e9bdbe9605410a8116a0 to your computer and use it in GitHub Desktop.
Download files from ADP.com as separate files
This file contains 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
// ==UserScript== | |
// @name ADP download | |
// @namespace https://github.com/GiorgioAresu | |
// @version 1.0.1 | |
// @description Download files from ADP as separate files | |
// @author You | |
// @match https://www.multidocs.it.adp.com/idp/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=adp.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
const processItem = el => new Promise((resolve, reject) => ( | |
async () => { | |
try { | |
const clickableArea = el.querySelector(".contextCell"); | |
clickableArea.click(); | |
await sleep(500); | |
const exportLink = document.querySelector("#contextMenu li[taskid=task_context_exportPDF] a"); | |
exportLink.click(); | |
resolve(); | |
} catch (error) { | |
reject(error); | |
} | |
})() | |
) | |
const selectedItems = document.querySelectorAll("tr:has(input[type=checkbox]:checked)"); | |
const itemsArray = Array.from(selectedItems); | |
if (itemsArray.length === 0) { | |
alert("Seleziona prima dei documenti") | |
return; | |
} | |
itemsArray.reduce((prev, curr) => prev.then(() => processItem(curr)), Promise.resolve()); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment