Created
October 29, 2019 01:33
-
-
Save SnacksOnAPlane/09b570eb4278098b502271b60150db0b to your computer and use it in GitHub Desktop.
Kindle book lister
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
// ==UserScript== | |
// @name Kindle Contents | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://read.amazon.com/ref=kcr_app_surl_cloudreader | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var db = window.openDatabase('K4W','3','books',2*1024*1024); | |
var items = [] | |
console.log(db); | |
db.transaction(function (tx) { | |
tx.executeSql('SELECT * FROM bookdata', [], function(tx, results) { | |
var len = results.rows.length; | |
for (var i = 0; i < len; i++) { | |
items.push(results.rows.item(i).title); | |
} | |
var rnd = Math.floor(Math.random() * len); | |
console.log(results.rows.item(rnd)); | |
generateTXT(items); | |
}); | |
}); | |
function generateTXT(items) { | |
let csv = ''; | |
// Loop the array of objects | |
for(let row = 0; row < items.length; row++){ | |
csv += items[row] + '\n'; | |
} | |
// Once we are done looping, download the .csv by creating a link | |
let link = document.createElement('a') | |
link.id = 'download-csv' | |
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(csv)); | |
link.setAttribute('download', 'yourfiletextgoeshere.txt'); | |
document.body.appendChild(link) | |
document.querySelector('#download-csv').click() | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment