42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
console.log("contentscript.js started!");
|
|
|
|
function getCurrentDate() {
|
|
let today = new Date();
|
|
let yyyy = today.getFullYear();
|
|
let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
|
|
let dd = String(today.getDate()).padStart(2, '0');
|
|
return yyyy + "-" + mm + "-" + dd;
|
|
}
|
|
|
|
function extractFileUrlsAndNames() {
|
|
return [];
|
|
}
|
|
|
|
function onStartedDownload(id) {
|
|
console.log(`Started downloading: ${id}`);
|
|
}
|
|
|
|
function onFailedToStartDownload(error) {
|
|
console.log(`Download failed: ${error}`);
|
|
}
|
|
|
|
|
|
let currentDate = getCurrentDate();
|
|
console.log(`contentscript.js: currentDate is ${currentDate}`);
|
|
|
|
let files = extractFileUrlsAndNames();
|
|
console.log(`contentscript.js: files is ${files}`);
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
// prefix files[i].filename with currentDate
|
|
let prefixedFilename = currentDate + " " + files[i].filename;
|
|
|
|
let downloading = browser.downloads.download({
|
|
url: files[i].url,
|
|
filename: prefixedFilename,
|
|
saveAs: (i == 0) // raise a path chooser dialog for the first file only; all later files will (hopefully!) be saved to the same folder
|
|
});
|
|
downloading.then(onStartedDownload, onFailedToStartDownload);
|
|
}
|
|
|
|
"contentscript.js has finished"; |