Last active
July 20, 2018 18:28
-
-
Save krhoyt/ec7a8f2b12c55e1b09a96bd24aae988a to your computer and use it in GitHub Desktop.
Parse Kindle Notes (July 2018)
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
// 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( ': ', ' ' ).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