-
-
Save spiaust/d4df71af9a9c69e5f4cd7a73e6d94ccb to your computer and use it in GitHub Desktop.
Download all your Kindle books before Feb 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Amazon Auto Download Books with Auto-Pagination | |
// @namespace http://tampermonkey.net/ | |
// @version 1.1 | |
// @description Automates the "Download & Transfer" process on Amazon Content Library and auto-paginates. | |
// @author Your Name | |
// @match https://www.amazon.com/hz/mycd/digital-console/contentlist/booksAll/dateDsc/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
function closeNotification() { | |
let notification = document.querySelector("span#notification-close"); | |
if (notification) { | |
notification.click(); | |
console.log("Closed notification."); | |
} | |
} | |
function pause(duration = 1000) { | |
return new Promise((resolve) => setTimeout(resolve, duration)); | |
} | |
async function downloadBooks() { | |
let menus = Array.from( | |
document.querySelectorAll('div[id*="DOWNLOAD_AND_TRANSFER_ACTION_"]') | |
).filter((el) => !el.id.endsWith("CONFIRM") && !el.id.endsWith("CANCEL")); | |
let inputs = Array.from( | |
document.querySelectorAll( | |
"ul[id^='download_and_transfer_list_'] > li[class^='ActionList-module_action_list_item__'] > div > label" | |
) | |
); | |
let buttons = Array.from( | |
document.querySelectorAll( | |
"div[id^='DOWNLOAD_AND_TRANSFER_DIALOG_'] div[class^='DeviceDialogBox-module_button_container__'] > div[id$='_CONFIRM']" | |
) | |
); | |
for (let i = 0; i < menus.length; i++) { | |
if (menus[i]) { | |
menus[i].click(); | |
await pause(); | |
if (inputs[i]) { | |
inputs[i].click(); | |
} | |
if (buttons[i]) { | |
buttons[i].click(); | |
} | |
await pause(); | |
closeNotification(); | |
} | |
} | |
console.log("All books on this page have been processed!"); | |
// Get current page number | |
let url = new URL(window.location.href); | |
let currentPage = parseInt(url.searchParams.get("pageNumber")) || 1; | |
let nextPage = currentPage + 1; | |
if (nextPage <= 168) { | |
// Change 168 if needed | |
console.log(`Going to next page: ${nextPage}...`); | |
url.searchParams.set("pageNumber", nextPage); | |
window.location.href = url.toString(); // Redirect to next page | |
} else { | |
console.log("Reached the last page. Stopping script."); | |
} | |
} | |
// Run script after a short delay to ensure page load | |
setTimeout(downloadBooks, 5000); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make this automatic with the help of Tampermonkey browser plugin:
Step 1: Install Tampermonkey
Tampermonkey is a browser extension that allows you to run custom JavaScript on websites.
π Install Tampermonkey:
Google Chrome: Tampermonkey Chrome Extension
Mozilla Firefox: Tampermonkey Firefox Add-on
Microsoft Edge: Tampermonkey Edge Extension
Step 2: Add the Script to Tampermonkey
Click on the Tampermonkey icon in your browser.
Select "Create a new script".
Delete the default template code.
Copy and paste the script below into the editor:
Click File > Save (or Ctrl + S / Cmd + S on Mac).
Close the Tampermonkey editor.
Step 3: Open Your Amazon Content Library
Go to Amazon Content Library
π https://www.amazon.com/hz/mycd/digital-console/contentlist/booksAll/dateDsc/
Manually navigate to the page number where you left off.
Example: If you've already processed page 1, go to: π https://www.amazon.com/hz/mycd/digital-console/contentlist/booksAll/dateDsc/?pageNumber=2
Step 4: Start the Script
Once you are on your starting page, the script will automatically run.
It will download books on the current page.
After finishing, it will automatically navigate to the next page.
It will continue running until page 168 (or the last page with books).
The script stops automatically when there are no more pages left.
Please note that this works best if you only have one kindle device registered to your account. My recommendation is to remove the other kindle devices from your account until you only have your default device, then run the script. After you are finished, you can re-register your other devices.