Files
send2ereader/static/download.html
2024-10-20 21:26:19 +02:00

137 lines
3.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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?s"/>
<script src="./common.js?a"></script>
</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>
</div>
<div class="center">
<div id="downloads">
<br/>
<div style="font-size: 1.3em;"><em>Downloads</em></div>
<a id="downloadlink" class="downloadlink"></a>
</div>
<div id="urls"></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/>
Last updated: 2024-10-20<br/>
</div>
</div>
<div id="logs"></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 urlsnode = document.getElementById('urls')
var siteurl = document.getElementById('siteurl')
var key = null
var pollTimer = null
function pollFile () {
if (!key) {
keyOutput.textContent = ''
downloads.style.display = 'none'
return
}
xhr('GET', './status/' + key, function (x) {
var data
try {
data = JSON.parse(x.responseText)
} catch (err) {
key = null
keyOutput.textContent = ''
downloads.style.display = 'none'
return
}
if (data.error) {
if (pollTimer) clearInterval(pollTimer)
key = null
keyOutput.textContent = ''
downloads.style.display = 'none'
}
var urls = data.urls && data.urls.length > 0 ? data.urls : null
if (data.file) {
downloads.style.display = 'block'
downloadlink.textContent = data.file.name
downloadlink.href = '/' + encodeURIComponent(data.file.name) + "?key=" + key
} else {
downloads.style.display = 'none'
}
if (urls) {
urlsnode.innerHTML = '<br/><div style="font-size: 1.3em;"><em>Urls</em></div>'
urls.forEach(function (url) {
var urllink = document.createElement("a")
urllink.href = url
urllink.target = '_blank'
urllink.textContent = url
urllink.className = "downloadlink"
var div = document.createElement('div')
div.appendChild(urllink)
urlsnode.appendChild(div)
})
}
})
}
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 = ''
if (pollTimer) clearInterval(pollTimer)
pollTimer = setInterval(pollFile, 5 * 1000)
} else {
key = null
keyOutput.textContent = ''
downloadlink.href = ''
}
keyGenBtn.blur()
})
}
window.onload = function () {
keyGenBtn.onclick = generateKey
generateKey()
}
siteurl.textContent = window.location.href
siteurl.href = siteurl.textContent
siteurl.target = '_self'
</script>
</body>
</html>