Make it work on nodejs 13

This commit is contained in:
2020-02-20 10:04:34 +00:00
parent ea153c6fd4
commit 3cc2c67949
3 changed files with 22 additions and 14 deletions

View File

@@ -4,22 +4,24 @@ This is a node script extracting E-Books from Amazon Kindle Cloud Reader.
Useful e.g. for being able to read on devices where the Cloud Reader doesn't work and for having a copy in an open format.
Works with Chrome/Chromium. Other browsers use different formats for the WebSQL file where the E-Books are stored for offline use.
Code is from this gists:
Antecedents:
* 1: https://gist.github.com/yangchenyun/a1c123935d82f5e25d57
* 2: https://gist.github.com/moodule/84140e557065ac3d73f669f120429ae1
1. https://gist.github.com/yangchenyun/a1c123935d82f5e25d57
2. https://gist.github.com/moodule/84140e557065ac3d73f669f120429ae1
3. https://github.com/d10r/kindle-fetch
I have just added minor usability improvements (e.g. cmdline switch for input file selection) and a package.json file.
`d10r` added minor usability improvements (e.g. cmdline switch for input file selection) and a package.json file.
I have just updated it to cope with newer versions of Node.
## Usage
This was successfully tested with nodejs v6 and v8 (will print ugly warnings with v8).
Doesn't work for me with nodejs v10 (and reportedly also not with v11).
This was successfully tested with Node v13.
<pre>
```
npm install
./main.js --help
</pre>
```
This generates HTML files with the book content in the directory you're in.

16
main.js
View File

@@ -289,8 +289,10 @@ db.all("select metadata from 'bookinfo'", function(err, rows) {
//var HtmlFile = path.join(os.tmpdir(), title.replace(/\s+/g, '-') + '.html');
var HtmlFile = title.replace(/\s+/g, '-') + '.html';
fs.writeFile(HtmlFile, HtmlHeader);
console.log("created the file with HTML headers.");
fs.writeFile(HtmlFile, HtmlHeader, (err) => {
if (err) throw err;
console.log("created the file with HTML headers.");
});
db.all("select id, piece, other from 'fragments' where asin='" + asin + "' order by id", function(err, rows) {
rows.forEach(function (row) {
@@ -309,11 +311,15 @@ db.all("select metadata from 'bookinfo'", function(err, rows) {
'dataUrl="' + image + '"',
'src="' + imageDataMap[image] + '"');
}
fs.appendFile(HtmlFile, uncompressedFragmentData);
fs.appendFile(HtmlFile, uncompressedFragmentData, (err) => {
if (err) throw err;
});
});
});
fs.appendFile(HtmlFile, '</body></html>');
console.log("created the file at: " + HtmlFile);
fs.appendFile(HtmlFile, '</body></html>', (err) =>{
if (err) throw err;
console.log("created the file at: " + HtmlFile);
});
});
});

View File

@@ -4,6 +4,6 @@
"main": "main.js",
"dependencies": {
"osenv": "^0.1.4",
"sqlite3": "^3.1.8"
"sqlite3": "^4.1.1"
}
}