Skip to content

Instantly share code, notes, and snippets.

@jkubecki
Last active October 3, 2025 18:11
Show Gist options
  • Save jkubecki/d61d3e953ed5c8379075b5ddd8a95f22 to your computer and use it in GitHub Desktop.
Save jkubecki/d61d3e953ed5c8379075b5ddd8a95f22 to your computer and use it in GitHub Desktop.

Revisions

  1. jkubecki revised this gist Jun 9, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ExportKindle.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // The following data should be run in the console while viewing the page https://read.amazon.com/
    // It will export a CSV file called "download" which can (and should) be renamed with a .csv extension

    var db = openDatabase('K4W', '2', 'thedatabase', 1024 * 1024);
    var db = openDatabase('K4W', '3', 'thedatabase', 1024 * 1024);

    getAmazonCsv = function() {
    // Set header for CSV export line - change this if you change the fields used
  2. jkubecki revised this gist Apr 21, 2018. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions ExportKindle.js
    Original file line number Diff line number Diff line change
    @@ -18,10 +18,10 @@ getAmazonCsv = function() {
    var authors = JSON.parse(results.rows.item(i).authors);
    var purchaseDate = new Date(results.rows.item(i).purchaseDate).toLocaleDateString();

    // Format/scrub the data

    // Remove double quotes from titles to not interfere with CSV 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
    @@ -33,6 +33,9 @@ getAmazonCsv = function() {

    // "Export" the data
    window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData);

    console.log("Sample Row:");
    console.log(results.rows.item(1));
    });
    });
    };
  3. jkubecki revised this gist Oct 10, 2016. 1 changed file with 31 additions and 31 deletions.
    62 changes: 31 additions & 31 deletions ExportKindle.js
    Original file line number Diff line number Diff line change
    @@ -4,37 +4,37 @@
    var db = openDatabase('K4W', '2', 'thedatabase', 1024 * 1024);

    getAmazonCsv = function() {
    // Set header for CSV export line - change this if you change the fields used
    var csvData = "ASIN,Title,Authors,PurchaseDate\n";

    db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM bookdata;', [], function(tx, results) {
    var len = results.rows.length;

    for (i = 1; i < len; i++) {
    // 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();

    // Format/scrub the data

    // Remove double quotes from titles to not interfere with CSV 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 CSV line
    csvData += '"' + asin + '","' + title + '","' + authorList + '","' + purchaseDate + '"\n'
    }

    // "Export" the data
    window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData);
    });
    });
    // Set header for CSV export line - change this if you change the fields used
    var csvData = "ASIN,Title,Authors,PurchaseDate\n";

    db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM bookdata;', [], function(tx, results) {
    var len = results.rows.length;

    for (i = 1; i < len; i++) {
    // 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();

    // Format/scrub the data

    // Remove double quotes from titles to not interfere with CSV 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 CSV line
    csvData += '"' + asin + '","' + title + '","' + authorList + '","' + purchaseDate + '"\n'
    }

    // "Export" the data
    window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData);
    });
    });
    };

    getAmazonCsv();
  4. jkubecki created this gist Oct 10, 2016.
    40 changes: 40 additions & 0 deletions ExportKindle.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    // The following data should be run in the console while viewing the page https://read.amazon.com/
    // It will export a CSV file called "download" which can (and should) be renamed with a .csv extension

    var db = openDatabase('K4W', '2', 'thedatabase', 1024 * 1024);

    getAmazonCsv = function() {
    // Set header for CSV export line - change this if you change the fields used
    var csvData = "ASIN,Title,Authors,PurchaseDate\n";

    db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM bookdata;', [], function(tx, results) {
    var len = results.rows.length;

    for (i = 1; i < len; i++) {
    // 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();

    // Format/scrub the data

    // Remove double quotes from titles to not interfere with CSV 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 CSV line
    csvData += '"' + asin + '","' + title + '","' + authorList + '","' + purchaseDate + '"\n'
    }

    // "Export" the data
    window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData);
    });
    });
    };

    getAmazonCsv();