Skip to content

Instantly share code, notes, and snippets.

@GiorgioAresu
Last active October 31, 2022 09:55
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 GiorgioAresu/16c526ceef14e9bdbe9605410a8116a0 to your computer and use it in GitHub Desktop.
Save GiorgioAresu/16c526ceef14e9bdbe9605410a8116a0 to your computer and use it in GitHub Desktop.
Download files from ADP.com as separate files
// ==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