Skip to content

Instantly share code, notes, and snippets.

@mattrix007
Forked from jkubecki/ExportKindle.js
Last active January 2, 2019 04:56
Show Gist options
  • Select an option

  • Save mattrix007/a49c5a562cfdb73873728e82e5c3115d to your computer and use it in GitHub Desktop.

Select an option

Save mattrix007/a49c5a562cfdb73873728e82e5c3115d to your computer and use it in GitHub Desktop.

Revisions

  1. mattrix007 revised this gist Jan 2, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ExportKindle.js
    Original file line number Diff line number Diff line change
    @@ -39,8 +39,8 @@ getAmazonCsv = function() {

    var win = window.open();
    win.document.write('<iframe src="' + 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData) +
    " frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; " +
    "width:100%; height:100%;" allowfullscreen></iframe>');
    '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; ' +
    'width:100%; height:100%;" allowfullscreen></iframe>');

    console.log("Sample Row:");
    console.log(results.rows.item(1));
  2. mattrix007 revised this gist Jan 2, 2019. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions ExportKindle.js
    Original file line number Diff line number Diff line change
    @@ -38,13 +38,15 @@ getAmazonCsv = function() {
    // from https://ourcodeworld.com/articles/read/682/what-does-the-not-allowed-to-navigate-top-frame-to-data-url-javascript-exception-means-in-google-chrome

    var win = window.open();
    win.document.write('<iframe src="' + 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData) + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
    win.document.write('<iframe src="' + 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData) +
    " frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; " +
    "width:100%; height:100%;" allowfullscreen></iframe>');

    console.log("Sample Row:");
    console.log(results.rows.item(1));
    });
    });
    };
    };

    getAmazonCsv();

  3. mattrix007 revised this gist Jan 2, 2019. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions ExportKindle.js
    Original file line number Diff line number Diff line change
    @@ -35,13 +35,11 @@ getAmazonCsv = function() {

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

    // from https://ourcodeworld.com/articles/read/682/what-does-the-not-allowed-to-navigate-top-frame-to-data-url-javascript-exception-means-in-google-chrome
    // from https://ourcodeworld.com/articles/read/682/what-does-the-not-allowed-to-navigate-top-frame-to-data-url-javascript-exception-means-in-google-chrome

    var win = window.open();
    win.document.write('<iframe src="' + 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData) + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');



    console.log("Sample Row:");
    console.log(results.rows.item(1));
    });
  4. mattrix007 revised this gist Jan 2, 2019. 1 changed file with 13 additions and 3 deletions.
    16 changes: 13 additions & 3 deletions ExportKindle.js
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ getAmazonCsv = function() {
    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 CSV double-quotes
    // Remove double quotes from titles to not interfere with CSV double-quotes
    title = title.replace(/"/g, '');


    @@ -32,12 +32,22 @@ getAmazonCsv = function() {
    }

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

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

    // from https://ourcodeworld.com/articles/read/682/what-does-the-not-allowed-to-navigate-top-frame-to-data-url-javascript-exception-means-in-google-chrome

    var win = window.open();
    win.document.write('<iframe src="' + 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData) + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');



    console.log("Sample Row:");
    console.log(results.rows.item(1));
    });
    });
    };

    getAmazonCsv();
    getAmazonCsv();


  5. @jkubecki 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));
    });
    });
    };
  6. @jkubecki 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();
  7. @jkubecki 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();