-
-
Save morja/776c3d244266b5628a8d8bb69ae239d2 to your computer and use it in GitHub Desktop.
Amazon Kindle Export
This file contains 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
// The following data should be run in the console while viewing the page https://read.amazon.com/ | |
// It will export a markdown file called "download" which can (and should) be renamed with a .md extension | |
// modified version of the original script: https://gist.github.com/jkubecki/d61d3e953ed5c8379075b5ddd8a95f22 | |
// this one exludes samples (EBSP), sorts the results by title and exports a list in markdown format | |
// it also adds links to the amazon pages of the books | |
var db = openDatabase('K4W', '2', 'thedatabase', 1024 * 1024); | |
getAmazonMarkdown = function() { | |
// Set header for markdown export line - change this if you change the fields used | |
var markdownData = []; | |
db.transaction(function(tx) { | |
tx.executeSql('SELECT * FROM bookdata;', [], function(tx, results) { | |
var len = results.rows.length; | |
for (i = 1; i < len; i++) { | |
if (results.rows.item(i).contentType == "EBSP") { continue; } | |
// Get the data | |
var asin = results.rows.item(i).asin; | |
var title = results.rows.item(i).title; | |
var authors = JSON.parse(results.rows.item(i).authors); | |
var purchaseDate = new Date(results.rows.item(i).purchaseDate).toLocaleDateString(); | |
// Remove double quotes from titles to not interfere with markdown double-quotes | |
title = title.replace(/"/g, ''); | |
// Concatenate the authors list - uncomment the next line to get all authors separated by ";" | |
// var authorList = authors.join(';'); | |
// OR Take only first author - comment the next line if you uncommented the previous one | |
var authorList = authors[0]; | |
// Write out the markdown line | |
//markdownData += '"' + title + '","' + authorList + '"\n'; | |
markdownData.push('* [' + title + '](https://www.amazon.com/exec/obidos/ASIN/' + asin + ') by ' + authorList); | |
} | |
markdownData.sort(); | |
var markdownDataTxt = "" | |
for (i = 0; i < markdownData.length; i++) { | |
markdownDataTxt += markdownData[i] + "\n"; | |
} | |
// "Export" the data | |
window.location = 'data:text/markdown;charset=utf8,' + encodeURIComponent(markdownDataTxt); | |
//console.log("Sample Row:"); | |
//console.log(results.rows.item(1)); | |
}); | |
}); | |
}; | |
getAmazonMarkdown(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment