Skip to content

Instantly share code, notes, and snippets.

@punchagan punchagan/kindle.js
Last active Aug 21, 2018

Embed
What would you like to do?
Readable view & Downloads for Kindle notebook (highlights) page
// Visit https://read.amazon.com/notebook
(function(){
var highlights_markdown = function(){
var markdown = "";
for (var i=0; i < highlights.length; i++){
markdown += "> " + highlights[i] + "\n\n";
var note = notes[i];
if (note !== "") {
markdown += note + "\n\n";
}
}
return markdown;
};
var highlights_orgmode = function(){
var orgmode = "";
for (var i=0; i < highlights.length; i++){
orgmode += "#+BEGIN_QUOTE\n";
orgmode += highlights[i] + "\n";
orgmode += "#+END_QUOTE\n\n";
var note = notes[i];
if (note !== "") {
orgmode += note + "\n\n";
}
}
return orgmode;
};
var add_download_links = function(){
var parent = $('.kp-notebook-bookcover-container').parent();
add_download_link(parent, 'markdown');
add_download_link(parent, 'x-org');
};
var add_download_link = function(parent, mimetype){
var a = $('<a />'),
blob, url, name;
if (mimetype == 'markdown') {
a.text('Download Markdown');
blob = new Blob([highlights_markdown()], {type : 'text/markdown'});
name = 'kindle-highlights.md';
} else if (mimetype == 'x-org'){
a.text('Download Org-Mode');
blob = new Blob([highlights_orgmode()], {type : 'text/markdown'});
name = 'kindle-highlights.org';
}
url = window.URL.createObjectURL(blob);
a.addClass('a-row').appendTo(parent).attr('href', url).attr('download', name);
};
var make_readable = function (){
$('#library').hide();
$('.kp-notebook-metadata').hide();
$('h3.kp-notebook-metadata').show().parent().toggleClass('a-span5');
$('.kp-notebook-bookcover-container').hide();
$('.a-declarative').hide();
$('.kp-notebook-row-separator').css('border-bottom',"none");
$('#annotations').css('float', 'none').css('max-width', '800px').css('margin', 'auto');
$('.a-scroller').css('overflow', 'inherit');
$('.a-size-small').hide();
};
make_readable();
var highlights = $('.kp-notebook-row-separator')
.find('#highlight').map(function(idx, x){return $(x).text();});
var notes = $('.kp-notebook-row-separator')
.find('#note').map(function(idx, x){return $(x).text();});
add_download_links();
})();
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.