2016-06-20 08:28:28 +12:00
|
|
|
|
2016-06-28 09:19:01 +12:00
|
|
|
import FimFic2Epub from './FimFic2Epub'
|
2016-08-15 21:11:20 +12:00
|
|
|
import { saveAs } from 'file-saver'
|
|
|
|
|
|
|
|
function blobToDataURL (blob, callback) {
|
|
|
|
let a = new FileReader()
|
|
|
|
a.onloadend = function (e) { callback(a.result) }
|
|
|
|
a.readAsDataURL(blob)
|
|
|
|
}
|
2016-06-20 08:28:28 +12:00
|
|
|
|
2016-06-21 09:04:08 +12:00
|
|
|
const STORY_ID = document.location.pathname.match(/^\/story\/(\d*)/)[1]
|
2016-06-20 08:28:28 +12:00
|
|
|
|
2016-06-28 09:19:01 +12:00
|
|
|
const ffc = new FimFic2Epub(STORY_ID)
|
2016-06-20 08:28:28 +12:00
|
|
|
|
2016-06-28 09:19:01 +12:00
|
|
|
const epubButton = document.querySelector('.story_container ul.chapters li.bottom a[title="Download Story (.epub)"]')
|
2016-06-21 09:04:08 +12:00
|
|
|
|
|
|
|
if (epubButton) {
|
2016-06-21 18:39:26 +12:00
|
|
|
epubButton.addEventListener('click', function (e) {
|
|
|
|
e.preventDefault()
|
2016-06-28 19:39:31 +12:00
|
|
|
ffc.download().then(() => {
|
2016-08-15 21:11:20 +12:00
|
|
|
ffc.getFile().then((file) => {
|
|
|
|
console.log('Saving file...')
|
|
|
|
if (typeof safari !== 'undefined') {
|
|
|
|
blobToDataURL(file, (dataurl) => {
|
|
|
|
document.location.href = dataurl
|
|
|
|
alert('Add .epub to the filename of the downloaded file')
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
saveAs(file, ffc.filename)
|
|
|
|
}
|
|
|
|
})
|
2016-06-28 19:39:31 +12:00
|
|
|
})
|
2016-06-21 18:39:26 +12:00
|
|
|
}, false)
|
2016-06-21 09:04:08 +12:00
|
|
|
}
|