Skip to content

Instantly share code, notes, and snippets.

@nicholasadamou
Last active February 21, 2025 12:32
Show Gist options
  • Save nicholasadamou/cfbadacf8fe1705683cb7d3b775379a2 to your computer and use it in GitHub Desktop.
Save nicholasadamou/cfbadacf8fe1705683cb7d3b775379a2 to your computer and use it in GitHub Desktop.
πŸ“₯ Download all your Kindle books before Feb 26, 2025! This script saves you hours by automating the process of downloading hundreds or even thousands of Kindle books from your Amazon Content Library. Instead of manually clicking through pages, opening menus, and selecting download options for each book, this script handles everything for you!

πŸ“š Kindle Book Downloader (Tampermonkey Script)

JavaScript

⚑ Automate Kindle Book Downloads Before Feb 26, 2025!

If you have hundreds or even thousands of Kindle books, manually downloading them is frustrating and time-consuming. This script automates the process, saving you hours by handling downloads with just one click. πŸš€

πŸ“ Features

βœ… Automatically selects and downloads all your Kindle books via Amazon's "Download & Transfer via USB" option.
βœ… Handles pagination to process all books across multiple pages.
βœ… Bypasses manual clicking, saving hours for large libraries.
βœ… Smart logging with emojis for better readability and debugging.

πŸš€ Installation

1️⃣ Install Tampermonkey

You'll need Tampermonkey to run this script. Install it for your browser:

2️⃣ Install the Script

  1. Open Tampermonkey Dashboard
  2. Click "Create a new script"
  3. Replace the default content with the Kindle Download script
  4. Click "Save" βœ…

πŸ›  How to Use

  1. Log in to your Amazon account.
  2. Go to your Kindle Content Library β†’ Amazon Kindle Content Library
  3. Click on the Download Kindle Books button to start downloading your books.
  4. The script will start downloading books one by one and navigating to the next page. πŸ“₯
  5. Leave it running until all books are processed. πŸŽ‰

⚠️ Important Notes

  • Deadline: Amazon will disable the ability to download Kindle books via USB after February 26, 2025. Download your books before it's too late! ⏳
  • Only works for Kindle books that allow USB transfer. Some books may be cloud-only.
  • Ensure pop-ups and notifications are not blocking actions.

πŸ› Troubleshooting

If the script is not working:
πŸ”Ή Ensure you’re on the correct Amazon page (Kindle Content Library).
πŸ”Ή Refresh the page and restart the script.
πŸ”Ή Check the browser console (F12 β†’ Console) for any error messages.

πŸ™πŸΌ Acknowledgements

This script would not have been possible without those who have contributed similar scripts before me. I would to list those for proper attribution:

// ==UserScript==
// @name πŸ“š Amazon Kindle Downloader
// @namespace http://tampermonkey.net
// @version 1.0.0
// @description πŸ“₯ Save hours by automating Kindle book downloads with a click of a button!
// @author Nicholas Adamou (nicholasadamou.com)
// @match https://www.amazon.com/hz/mycd/digital-console/contentlist/booksAll/dateDsc/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=amazon.com
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @run-at document-idle
// @license MIT
// ==/UserScript==
(function () {
'use strict';
console.log("πŸš€ Kindle Downloader Script Loaded");
/**
* Pauses execution for a specified duration.
* @param {number} [duration=1000] - Duration to pause in milliseconds.
* @returns {Promise<void>} A promise that resolves after the specified duration.
*/
function pause(duration = 1000) {
return new Promise(resolve => setTimeout(resolve, duration));
}
/**
* Closes any active notification popups on the page.
*/
function closeNotification() {
const closeNote = document.querySelector("span#notification-close");
if (closeNote) {
closeNote.click();
console.log("πŸ”• Closed notification.");
}
}
/**
* Initiates the download process for all books on the current page.
*/
async function downloadBooksOnPage() {
const menus = Array.from(
document.querySelectorAll('div[class*="Dropdown-module_dropdown_container"]')
).map(container =>
Array.from(container.children).find(child => child.innerHTML.includes("DOWNLOAD_AND_TRANSFER_DIALOG"))
).filter(Boolean);
for (const menu of menus) {
try {
const dialog = menu.querySelector("div[id^='DOWNLOAD_AND_TRANSFER_DIALOG_']");
if (!dialog) {
console.warn("⚠️ No dialog found for menu.");
continue;
}
const parts = dialog.id.split("_");
const asin = parts[parts.length - 1];
console.log(`πŸ“– Processing book: ASIN ${asin}`);
menu.click();
await pause(500);
const inputSelector = `ul#download_and_transfer_list_${asin} li[class^='ActionList-module_action_list_item__'] > div > label`;
const input = document.querySelector(inputSelector);
if (!input) {
console.warn(`⚠️ No download option found for ASIN ${asin}`);
continue;
}
input.click();
await pause(500);
const buttonSelector = `div[id^='DOWNLOAD_AND_TRANSFER_DIALOG_${asin}'] div[class^='DeviceDialogBox-module_button_container__'] > div[id$='_CONFIRM']`;
const button = document.querySelector(buttonSelector);
if (!button) {
console.warn(`⚠️ No confirm button found for ASIN ${asin}`);
continue;
}
button.click();
await pause(1000);
closeNotification();
await pause(500);
console.log(`βœ… Successfully triggered download for ASIN ${asin}`);
} catch (error) {
console.error(`❌ Error processing book ASIN ${asin}: ${error.message}`);
}
}
}
/**
* Navigates to the next page of books if available.
* @returns {Promise<boolean>} True if there is another page, false otherwise.
*/
async function goToNextPage() {
const currentPage = document.querySelector("a.page-item.active");
if (!currentPage) {
console.warn("⚠️ Could not find the active page.");
return false;
}
const nextPage = currentPage.nextElementSibling;
if (nextPage && nextPage.classList.contains("page-item")) {
console.log("➑️ Navigating to the next page...");
nextPage.click();
await pause(5000);
return true;
} else {
console.log("🏁 No more pages to process.");
return false;
}
}
/**
* Starts the book download process across all pages.
*/
async function startDownloadProcess() {
console.log("πŸ“₯ Downloading books from the current page...");
while (true) {
await downloadBooksOnPage();
const hasNext = await goToNextPage();
if (!hasNext) break;
}
console.log("πŸŽ‰ Script completed. All books processed.");
}
/**
* Adds a button to the webpage to trigger the download process.
*/
function addDownloadButton() {
const button = document.createElement('button');
button.innerText = 'Download Kindle Books';
button.style.position = 'fixed';
button.style.top = '20px';
button.style.right = '20px';
button.style.padding = '10px';
button.style.fontSize = '16px';
button.style.backgroundColor = '#4CAF50';
button.style.color = 'white';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
button.style.zIndex = 9999;
button.addEventListener('click', startDownloadProcess);
document.body.appendChild(button);
}
window.addEventListener('load', addDownloadButton);
GM_addStyle(`
button {
font-family: Arial, sans-serif;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment