Skip to content

Instantly share code, notes, and snippets.

@krhoyt krhoyt/kindle.js
Last active Jul 20, 2018

Embed
What would you like to do?
Parse Kindle Notes (July 2018)
// Phase 1 - Create additional elements
let dummy = document.createElement( 'textarea' );
document.body.appendChild( dummy );
// Phase 2 - Parse, format, and place on clipboard
// Repeat as needed for each selected book
let notes = document.querySelectorAll( 'span[id=\'highlight\']' );
let pages = document.querySelectorAll( 'span[id=\'annotationHighlightHeader\']' );
let output = '';
for( let n = 0; n < notes.length; n++ ) {
let page = pages[n].innerHTML.split( '|' )[1].replace( ':&nbsp;', ' ' ).trim();
output = output + page + ': ' + notes[n].innerHTML.trim() + '\n\n';
}
dummy.value = output;
dummy.select();
document.execCommand( 'copy' );
// Setup for next pass
output = '';
// Phase 3 - Control+V into the destination
// Phase 4 - If you want full size images of the book covers
let library = document.querySelector( '#kp-notebook-library' );
let images = library.querySelectorAll( 'img.kp-notebook-cover-image' );
let titles = document.querySelectorAll( 'h2.kp-notebook-searchable' );
// Phase 4 - Parse, format, output
// Runs through library in a single pass
output = '';
// Title: Image URL
for( let i = 0; i < images.length; i++ ) {
output = output + titles[i].innerText.trim() + ': ' + images[i].src.replace( '._SY160', '' ) + '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.