Skip to content

Instantly share code, notes, and snippets.

@fdebijl
Last active July 11, 2022 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fdebijl/c75e0530ba9d0759098026205c3d07e2 to your computer and use it in GitHub Desktop.
Save fdebijl/c75e0530ba9d0759098026205c3d07e2 to your computer and use it in GitHub Desktop.
Simon Stålenhag Wallpaper Downloader
(() => {
'use strict';
const dqs = document.querySelector.bind(document);
const dqsa = document.querySelectorAll.bind(document);
if (dqs('#jesus') || dqs('span.style9')) {
(dqs('#jesus') || dqs('span.style9')).remove();
}
const anchors = dqsa('a');
const downloadlink = document.createElement('a');
const linksToDownload = [];
const counter = document.createElement('div');
counter.style.cssText = `
display: flex;
position: fixed;
justify-content: center;
align-items: center;
top: 0;
right: 0;
padding: .4em 1.6em;
font-size: 16pt;
width: auto;
min-width: 5vw;
height: 5vh;
border-radius: 0 0 0 2em;
background: #FFF;
box-shadow: -4px 5px 13px 0px rgba(0,0,0,0.5);
`;
counter.id = 'jesus';
dqs('#god').appendChild(counter);
// Find all images that link to the full-res versions. Every other version is a detailed (i.e. zoomed-in) version of the same image.
for (let i = 0; i < anchors.length; i++) {
if (anchors[i].href && anchors[i].href.includes('bilderbig') && !linksToDownload.includes(anchors[i].href)) {
linksToDownload.push(anchors[i].href);
};
}
dqs('#jesus').innerText = `Downloading 0/${linksToDownload.length}`;
// Download all the images we found earlier - one every 2000 milliseconds to prevent congestion
let linkIndex = 0;
let downloadInterval = setInterval(() => {
if (linkIndex === linksToDownload.length) {
console.log("Done downloading");
clearInterval(downloadInterval);
dqs('#jesus').innerText = `Done downloading.`;
setTimeout(() => {
dqs('#jesus').remove();
}, 5000);
}
dqs('#jesus').innerText = `Downloading ${linkIndex + 1}/${linksToDownload.length}\nTime remaining: ${SecondsToFullTime((linksToDownload.length - linkIndex + 1) * 2)}`;
downloadlink.download = linksToDownload[linkIndex].split('/')[1].split('.')[0];
downloadlink.href = linksToDownload[linkIndex];
downloadlink.click();
linkIndex++;
}, 2000);
const SecondsToFullTime = seconds => {
const remainingHours = pad(Math.round(seconds / 3600 % 60));
const remainingMinutes = pad(Math.round(seconds / 60 % 60));
const remaingSeconds = pad(Math.round(seconds % 60));
return remainingHours + ':' + remainingMinutes + ':' + remaingSeconds;
}
const pad = int => {
return int > 9 ? int : '0' + int;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment