Skip to content

Instantly share code, notes, and snippets.

@d1820
Created February 20, 2024 18:52
Show Gist options
  • Save d1820/21f5d078976b576ead45c1a6f75a39b2 to your computer and use it in GitHub Desktop.
Save d1820/21f5d078976b576ead45c1a6f75a39b2 to your computer and use it in GitHub Desktop.
Bookmarklets to auto advance pages from Ebooks online and save them as images
javascript: (function()
{
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/html2canvas.min.js';
document.head.appendChild(script);
var link = document.createElement("a");
document.body.appendChild(link);
var counter = 1;
function nextPage()
{
var event = new KeyboardEvent('keydown', {
key: 'ArrowRight',
keyCode: 39,
which: 39
});
window.dispatchEvent(event);
setTimeout(() =>
{
takeshot();
}, 3000);
}
function getActiveFrame()
{
var activeFrame = null;
var maxCount = 3;
var tryCount = 0;
while (!activeFrame && tryCount < maxCount)
{
frames.forEach(f =>
{
var styles = window.getComputedStyle(f);
if (styles.visibility === 'visible')
{
activeFrame = f;
return;
}
});
tryCount++;
}
return activeFrame;
}
function takeshot()
{
var container = document.getElementById('kr-renderer');
var frames = container.getElementsByTagName('iframe');
var activePage;
if (frames.length > 0)
{
var activeFrame = getActiveFrame();
activePage = activeFrame.contentWindow.document.getElementsByClassName('amzn-sliced-inimg-div')[0];
} else
{
activePage = document.getElementsByClassName('kg-full-page-img')[0];
}
html2canvas(activePage).then((canvas) =>
{
var base64ImageData = canvas.toDataURL('image/png');
link.setAttribute("href", base64ImageData);
link.setAttribute("download", counter);
link.click();
counter++;
nextPage();
});
}
setTimeout(() =>
{
takeshot();
}, 3000);
})();
javascript: (function()
{
function nextPage()
{
var event = new KeyboardEvent('keydown', {
key: 'ArrowRight',
keyCode: 39,
which: 39
});
window.dispatchEvent(event);
setTimeout(() =>
{
nextPage();
}, 1000);
}
nextPage();
})();

Saving ebooks as images

Saving Certain Ebook providers books

Some ebooks are image based and have certain DRM rights added to them, even though you PAID for them. These bookmarklets allows for capturing those EBooks YOU own.

Image based books

  • Install the advance-and-download-ebook bookmarklet as a favorite in your bookmarks bar.
  • Navigate to the EBook you bought and open it in the web browser
  • Click the bookmarklet. It will start to page and download each page as an image.
    • NOTE: if nothing starts to download, this means the EBook you are viewing is not supported for download with this bookmarklet.
    • Press F5 to reset the page
  • Once all pages have beeb downloaded and the EBook no longer advances. Press F5 to stop the downloading and paging.

Converting your images to a PDF

  • In windows go to your downloads folder and select all the images. Make sure to order them by modified date
  • Once selected right click and choose Print
  • Adjust the print settings for the proper layout
  • Select PDF as the output printer

Text based books

  • Install the advance-ebook bookmarklet as a favorite in your bookmarks bar.
  • Navigate to the EBook you bought and open it in the web browser
  • In windows open the Snipping Tool and set to record mode
  • Create the rectangle with the Snipping Tool that captures the whole area of the book
  • Start recording
  • Click the bookmarklet. It will start to page through each page in 1 second intervals.
  • Once all the pages have been paged through, stop recording

Converting the MP4 to Images

Converting your images to a PDF

  • In windows go to your video save output folder and select all the images. Make sure to order them by modified date
  • Once selected right click and choose Print
  • Adjust the print settings for the proper layout
  • Select PDF as the output printer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment