Sleazy Fork is available in English.

LoversLab Download All

Adds a download all button to loverslab

< Feedback on LoversLab Download All

Review: OK - script works, but has bugs

§
Posted: 2023.02.15.

There is a problem with your script: some files are skipped (if bad internet connexion). This is my case so I made a modification to your script (I know this is surely not the good way to script but my Javascript is bad)
This is my code :

// ==UserScript==
// @name LoversLab Download All
// @namespace N/A
// @version 0.2
// @description Adds a download all button to loverslab
// @author ImNotJackie
// @match https://www.loverslab.com/*?do=download
// @icon https://www.google.com/s2/favicons?sz=64&domain=loverslab.com
// @grant none
// @license MIT
// ==/UserScript==

(function() {
'use strict';

var newRow = document.getElementsByClassName("ipsDataItem")[0].cloneNode(true);
var amount = document.querySelector("#ipsLayout_mainArea > div:nth-child(2) > div > p").innerHTML.toString();
var size = document.getElementsByClassName("ipsType_reset ipsDataItem_meta");
var num = 0;
for(i = 1; i < size.length; i++){
var test = size[i].textContent.toString().replace("\n ","");
test.substring(0, test.indexOf("\n") - 3);
var temp = parseFloat(test.substring(0, 5));
if(test.includes("kB") == true){
temp = temp / 10000;
}
if(test.includes("MB") == true){
temp = temp / 1000;
}
num = num + temp;
}

var lst_link = [];

num = Math.round(num * 100) / 100
newRow.firstElementChild.children[1].textContent = "\n " + num + " GB Estimated";
newRow.firstElementChild.firstElementChild.firstElementChild.textContent = "Download all " + amount;
newRow.lastElementChild.className = "downloadAll";
newRow.lastElementChild.lastElementChild.removeAttribute("href");
function downloadAll (zEvent) {
var buttons = document.getElementsByClassName("ipsButton ipsButton_primary ipsButton_small");
for(i = 1; i < buttons.length; i++){
(function(i){
//put the link of the button on lst_link
lst_link.push(buttons[i].href);
}(i));
}
console.log(lst_link);
download_link_list(lst_link);
}

async function downloadFromLink(link) {
console.log("downloadFromLink");
const response = await fetch(link, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
//console.log of the name of the file we are downloading
console.log(response.headers.get('Content-Disposition').split("filename=")[1]);
//we download the file
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
//this is the name of the file we are downloading
a.download = response.headers.get('Content-Disposition').split("filename=")[1];
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
}


function download_link_list(lst_link){
console.log("download_link_list");
//we download all the links in the list one by one (we wait for the download to finish before starting the next one)
for(i = 0; i < lst_link.length; i++){
(function(i){
downloadFromLink(lst_link[i]);
}(i));
}
}

var myDiv = newRow.lastElementChild.lastElementChild;
if (myDiv) {
myDiv.addEventListener ("click", downloadAll , false);
}
document.querySelector("#ipsLayout_mainArea > div:nth-child(2) > div > ul").insertBefore(newRow, document.querySelector("#ipsLayout_mainArea > div:nth-child(2) > div > ul").firstChild);
})();

§
Posted: 2023.02.18.

I have made an other script to dl files :

https://greasyfork.org/fr/scripts/460082-loverslab-download-all

Post reply

Sign in to post a reply.