Skip to content

Instantly share code, notes, and snippets.

@lazanet
Last active February 24, 2022 00:47
Show Gist options
  • Save lazanet/ac17cf427c13672dab4aa102440a3df8 to your computer and use it in GitHub Desktop.
Save lazanet/ac17cf427c13672dab4aa102440a3df8 to your computer and use it in GitHub Desktop.
Download slides from slideshare
function getHighestResImg(element) {
if (element.getAttribute('srcset')) {
let highResImgUrl = '';
let maxRes = 0;
let imgWidth, urlWidthArr;
element.getAttribute('srcset').split(',').forEach((item) => {
urlWidthArr = item.trim().split(' ');
imgWidth = parseInt(urlWidthArr[1]);
if (imgWidth > maxRes) {
maxRes = imgWidth;
highResImgUrl = urlWidthArr[0];
}
});
return highResImgUrl;
} else {
return element.getAttribute('src');
}
}
function get() {
if (i >= num) {
commands = ""
for (let j = 0; j < num; j++) {
commands += "wget " + lista[j] + ";\n";
}
commands += "convert `ls -1v|grep .jpg` file.pdf;"
console.log(commands);
return;
}
let curr = getHighestResImg(document.querySelectorAll(".slide-image")[i++]);
lista.push(curr);
setTimeout(get, 200);
}
function handle() {
lista = [];
num = document.querySelectorAll(".slide-image").length;
for (let j = 1; j < num; j++) {
document.querySelector("#next-slide").click();
}
for (let j = 1; j < num; j++) {
document.querySelector("#previous-slide").click();
}
i = 0;
setTimeout(get, 200);
}
handle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment