Skip to content

Instantly share code, notes, and snippets.

@clupasq
Last active April 23, 2024 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clupasq/290953d76e73dc41db98f2bb7e8d8095 to your computer and use it in GitHub Desktop.
Save clupasq/290953d76e73dc41db98f2bb7e8d8095 to your computer and use it in GitHub Desktop.
This is a small JS script that automatically downloads all the images in a WhatsApp conversation
// Script to download images from WhatsApp
//
// Steps to use:
// 1. Open up the conversation you want to download pics from
// 2. Open the leftmost image you want to download (the script
// will download and advance to the next image until the last
// image is reached.
// 3. Open the developer console and paste the script in it
// 4. Click OK on the "Download multiple files" browser prompt
// (if it appears)
//
// Tested in Chrome 124
(function () {
var dlTimeout = 1500;
var nextTimeout = 100;
var maxDownloads = 1306;
var downloadCount = 1;
var downloadMenu = document.querySelector('div[aria-label="Menu"]');
var download = function () {
if (downloadMenu) {
downloadMenu.click();
}
setTimeout(() => {
try {
var downloadBtn = document.querySelector('div[aria-label="Download"]');
var nextBtn = document.querySelector('div[aria-label="Next"]');
// console.log(downloadBtn, nextBtn);
if (downloadBtn) {
downloadBtn.click();
setTimeout(() => {
nextBtn.click();
console.log("downloadCount: = " + downloadCount);
downloadCount += 1;
if (downloadCount <= maxDownloads) {
download();
}
}, nextTimeout);
} else {
// if download button not available, continue with previous photo...
nextBtn.click();
download();
}
} catch (ex) {
console.error(ex);
var nextBtn = document.querySelector('div[aria-label="Next"]');
nextBtn.click();
}
}, dlTimeout);
};
download();
})();
@clupasq
Copy link
Author

clupasq commented Apr 23, 2024

@z3nth10n Thanks! I've updated the gist based on your proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment