-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
99 additions
and
252 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
bundle.js | ||
yarn.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
<script src="/bundle.js"></script> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title>anki-apkg-export demo</title> | ||
</head> | ||
<body> | ||
<button id="buttonSimple">simple</button> | ||
<button id="buttonAjax">ajax</button> | ||
<input type="file" /> | ||
|
||
<script src="/bundle.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,59 @@ | ||
import { saveAs } from 'file-saver'; | ||
|
||
import AnkiExport from '../../src'; | ||
// import AnkiExport from 'anki-apkg-export'; | ||
|
||
const apkg = new AnkiExport('deck-name'); | ||
|
||
apkg.addCard('card #1 front', 'card #1 back'); | ||
apkg.addCard('card #2 front', 'card #2 back'); | ||
|
||
apkg | ||
.save() | ||
.then(zip => { | ||
saveAs(zip, 'output.apkg'); | ||
}) | ||
.catch(err => console.log(err.stack || err)); | ||
import AnkiExport from 'anki-apkg-export'; | ||
import { saveAs } from 'file-saver'; | ||
import 'script-loader!sql.js/dist/sql-asm'; | ||
|
||
(async () => { | ||
const sql = await initSqlJs(); | ||
|
||
document.querySelector('#buttonSimple').addEventListener('click', () => { | ||
handleSimple(sql); | ||
}); | ||
|
||
document.querySelector('#buttonAjax').addEventListener('click', () => { | ||
handleAjax(sql); | ||
}); | ||
|
||
document.querySelector('input').addEventListener('change', e => { | ||
handleInput(sql, e.target.files[0]); | ||
}); | ||
})(); | ||
|
||
async function handleSimple(sql) { | ||
const apkg = new AnkiExport('deck-name', {}, sql); | ||
|
||
apkg.addCard('card #1 front', 'card #1 back'); | ||
apkg.addCard('card #2 front', 'card #2 back'); | ||
|
||
const zip = await apkg.save(); | ||
saveAs(zip, 'output.apkg'); | ||
} | ||
|
||
async function handleAjax(sql) { | ||
const apkg = new AnkiExport('deck-name-ajax', {}, sql); | ||
|
||
const response = await fetch('https://raw.githubusercontent.com/ewnd9/anki-apkg-export/39ebdd664ab23b5237eee95b7dd88c457e263a20/example/assets/anki.png'); | ||
const myBlob = await response.blob(); | ||
|
||
apkg.addMedia('anki.png', myBlob); | ||
apkg.addCard('card #1 with image <img src="anki.png" />', 'card #1 back'); | ||
|
||
const zip = await apkg.save() | ||
saveAs(zip, 'output.apkg'); | ||
} | ||
|
||
async function handleInput(sql, file) { | ||
const apkg = new AnkiExport('deck-name', {}, sql); | ||
const reader = new FileReader(); | ||
|
||
reader.onload = async e => { | ||
const file = e.target.result; | ||
|
||
apkg.addMedia('anki.png', file); | ||
apkg.addCard('card #1 with image <img src="anki.png" />', 'card #1 back'); | ||
|
||
const zip = await apkg.save() | ||
saveAs(zip, 'output.apkg'); | ||
}; | ||
|
||
reader.readAsArrayBuffer(file); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"build": "webpack" | ||
"build": "webpack --mode production" | ||
}, | ||
"dependencies": { | ||
"anki-apkg-export": "^3.0.1", | ||
"babel-loader": "^6.2.4", | ||
"babel-preset-es2015": "^6.6.0", | ||
"file-saver": "^1.3.3" | ||
"anki-apkg-export": "file:../../", | ||
"file-saver": "^2.0.2" | ||
}, | ||
"devDependencies": { | ||
"script-loader": "^0.6.1", | ||
"webpack": "^1.12.14" | ||
"script-loader": "^0.7.2", | ||
"webpack": "^4.41.5", | ||
"webpack-cli": "^3.3.10" | ||
} | ||
} |
Oops, something went wrong.