Files
send2ereader/download.html
T

122 lines
3.1 KiB
HTML

<!doctype html>
<html>
<head>
<title>Send to Kobo/Kindle</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="/style.css?l"/>
</head>
<body>
<div class="wrapper">
<h1 class="center">Send to Kobo/Kindle</h1>
<div class="center">
<div style="font-size: 1.3em;">Unique key:</div>
<div id="key">
<span id="keyoutput">––––</span>
<button id="keygen" title="Generate new key">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path d="M19.146 4.854l-1.489 1.489A8 8 0 1 0 12 20a8.094 8.094 0 0 0 7.371-4.886 1 1 0 1 0-1.842-.779A6.071 6.071 0 0 1 12 18a6 6 0 1 1 4.243-10.243l-1.39 1.39a.5.5 0 0 0 .354.854H19.5A.5.5 0 0 0 20 9.5V5.207a.5.5 0 0 0-.854-.353z"/>
</svg>
</button>
</div>
<br/>
</div>
<div class="center" id="downloads">
<div style="font-size: 1.3em;"><em>Downloads</em></div>
<br/>
<div><a id="downloadlink"></a></div>
<br/>
</div>
<hr/>
<br/>
<div class="center">
Visit this on other devices to send ebooks to this ereader:<br/><a id="siteurl">https://send.djazz.se</a><br/>
<br/>
Created by djazz. Source code on <a href="https://github.com/daniel-j/send2ereader" target="_blank">Github</a><br/>
</div>
</div>
<script type="text/javascript">
var keyOutput = document.getElementById('keyoutput')
var keyGenBtn = document.getElementById('keygen')
var downloads = document.getElementById('downloads')
var downloadlink = document.getElementById('downloadlink')
var siteurl = document.getElementById('siteurl')
var key = null
var pollTimer = null
function xhr(method, url, cb) {
var x = new XMLHttpRequest()
x.onload = function () {
cb(x)
}
x.onerror = function () {
cb(x)
}
x.open(method, url, true)
x.send(null)
}
function pollFile () {
xhr('GET', '/status/' + key, function (x) {
var data
try {
data = JSON.parse(x.responseText)
} catch (err) {
keyOutput.textContent = '––––'
key = null
downloads.style.display = 'none'
return
}
if (data.error) {
if (pollTimer) clearInterval(pollTimer)
key = null
keyOutput.textContent = '––––'
downloads.style.display = 'none'
}
if (data.file) {
downloadlink.textContent = data.file.name
downloads.style.display = 'block'
} else {
downloads.style.display = 'none'
}
})
}
function generateKey () {
keyOutput.textContent = '––––'
if (pollTimer) clearInterval(pollTimer)
downloads.style.display = 'none'
xhr('POST', '/generate', function (x) {
if (x.responseText !== 'error' && x.status === 200) {
key = x.responseText
keyOutput.textContent = key
downloadlink.href = '/download/' + key
if (pollTimer) clearInterval(pollTimer)
pollTimer = setInterval(pollFile, 5 * 1000)
} else {
keyOutput.textContent = '––––'
key = null
downloadlink.href = ''
}
keyGenBtn.blur()
})
}
window.onload = function () {
keyGenBtn.onclick = generateKey
generateKey()
}
siteurl.textContent = window.location.origin
siteurl.href = siteurl.textContent
siteurl.target = '_self'
</script>
</body>
</html>