Skip to content

Instantly share code, notes, and snippets.

@markhowellsmead
Last active January 30, 2025 13:14
Show Gist options
  • Save markhowellsmead/15661e90d4d72f10c36ebdab7d3a0a2a to your computer and use it in GitHub Desktop.
Save markhowellsmead/15661e90d4d72f10c36ebdab7d3a0a2a to your computer and use it in GitHub Desktop.
Download full-size images from a Jimdo page containing galleries
/**
* Run this in the browser's developer console.
* Provided with no guarantees! Worked perfectly when published.
*
* mark-at-sayhello.ch / 30.1.2025
*/
(()=> {
let galleryCounters = {}; // Stores counters for each gallery legend
let downloadWithDelay = async (links, legend) => {
for (let i = 0; i < links.length; i++) {
let url = links[i].getAttribute('data-href');
console.log(` Downloading: ${url}`);
let parts = url.split('/');
let filename = parts.slice(-2).join('-'); // Last two URL parts joined with a dash
// Keep special characters (ä, ö, ü, etc.), but remove problematic filename chars
let cleanLegend = legend.replace(/[\/:*?"<>|]/g, '');
let finalFilename = `${cleanLegend} ${String(galleryCounters[legend]).padStart(2, '0')} - ${filename}`; // Add iteration number
galleryCounters[legend]++; // Increment counter for this gallery
try {
let res = await fetch(url);
let blob = await res.blob();
let a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = finalFilename;
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(a.href);
document.body.removeChild(a);
} catch (err) {
console.error(` Failed to download: ${url}`, err);
}
await new Promise(resolve => setTimeout(resolve, 500)); // Pause for 500ms before the next download
}
};
document.querySelectorAll('.cc-m-gallery-container').forEach(async (container) => {
let gallery = container.closest('.j-gallery'); // Find the closest .j-gallery
let legend = gallery ? gallery.previousElementSibling?.classList.contains('j-header') ? gallery.previousElementSibling.textContent.trim() : 'unknown' : 'unknown';
if (!galleryCounters[legend]) {
galleryCounters[legend] = 1; // Initialize counter for this gallery
}
let links = Array.from(container.querySelectorAll('a[data-href]'));
console.log(`Gallery "${legend}": ${links.length} images`);
await downloadWithDelay(links, legend); // Download each image sequentially with a delay
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment