93 lines
1.9 KiB
HTML
93 lines
1.9 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Send to Kobo</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"/>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="wrapper">
|
|
<h1 class="center">Send to Kobo</h1>
|
|
|
|
<div class="center">
|
|
Unique key:
|
|
<output id="key">- - - -</output>
|
|
<br/>
|
|
<button id="keygen">Generate new key</button>
|
|
</div>
|
|
<br/>
|
|
<hr/>
|
|
<br/>
|
|
<div class="center" id="downloads">
|
|
<a id="downloadlink"></a>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var keyOutput = document.getElementById('key')
|
|
var keyGenBtn = document.getElementById('keygen')
|
|
var downloads = document.getElementById('downloads')
|
|
var downloadlink = document.getElementById('downloadlink')
|
|
var key = null
|
|
var pollTimer = null
|
|
|
|
function xhr(url, cb) {
|
|
var x = new XMLHttpRequest()
|
|
x.onload = function () {
|
|
cb(x)
|
|
}
|
|
x.open('GET', url, true)
|
|
x.send(null)
|
|
}
|
|
|
|
function pollFile () {
|
|
xhr('/status/' + key, function (x) {
|
|
var data
|
|
try {
|
|
data = JSON.parse(x.responseText)
|
|
} catch (err) { }
|
|
if (data && data.error) {
|
|
if (pollTimer) clearInterval(pollTimer)
|
|
key = null
|
|
keyOutput.textContent = '- - - -'
|
|
}
|
|
if (data && 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('/generate', function (x) {
|
|
keyOutput.textContent = x.responseText
|
|
if (x.responseText !== 'error') {
|
|
key = x.responseText
|
|
downloadlink.href = '/download/' + key
|
|
if (pollTimer) clearInterval(pollTimer)
|
|
pollTimer = setInterval(pollFile, 5 * 1000)
|
|
} else {
|
|
key = null
|
|
downloadlink.href = ''
|
|
}
|
|
keyGenBtn.blur()
|
|
})
|
|
}
|
|
|
|
window.onload = function () {
|
|
keyGenBtn.onclick = generateKey
|
|
generateKey()
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|