Skip to content

Instantly share code, notes, and snippets.

@pkulak
Created September 30, 2024 14:46
Show Gist options
  • Save pkulak/6eb46e9a4e5a5aa2f3ddb95dbd98e807 to your computer and use it in GitHub Desktop.
Save pkulak/6eb46e9a4e5a5aa2f3ddb95dbd98e807 to your computer and use it in GitHub Desktop.
Download all your Kindle books automation.
// How to use this?
// * Navigate to the first page of your "Digital Content -> Books" section.
// * Figure out where your kindle is in the list and update `deviceIndex` below.
// * Open up a dev console and paste all of this in.
// * Type `downloadAll(0);` into the dev console and hit enter.
// * Repeat the above step for each page of books.
//
// This is tested in latest Firefox, and will probably break the second Amazon
// changes anything on the pages used.
// change this to the zero-based index of your kindle in the list
const deviceIndex = 0
clickRadio = () => {
const radio = [...document.querySelectorAll("input[type=radio]")].filter((el) => el.checkVisibility({
visibilityProperty: true
}))[deviceIndex];
radio.click();
setTimeout(clickDownload, 1000);
};
clickDownload = () => {
const download = [...document.querySelectorAll("div[id^=DOWNLOAD_AND_TRANSFER] > span")].filter((el) => el.checkVisibility({
visibilityProperty: true
}))[1];
download.click();
setTimeout(() => {
document.querySelector("span#notification-close").click();
}, 1000);
};
download = () => {
const options = document.querySelectorAll("div[class^='Dropdown-module_dropdown_container'][style*='visibility: visible;'] > div");
for (const el of options) {
if (!el.innerText.includes("Download")) {
console.log("skipping");
continue;
}
el.querySelector("span").click();
setTimeout(clickRadio, 1000);
break;
}
};
downloadAll = (index) => {
[...document.querySelectorAll(".dropdown_title")][index].click();
setTimeout(download, 1000);
if (index < 24) {
setTimeout(() => { downloadAll(index + 1) }, 5000);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment