mobi ios workaround, improve style up recieve page
This commit is contained in:
67
upload.html
67
upload.html
@@ -14,7 +14,7 @@
|
||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||
<table style="margin: 0 auto;" cellpadding=0 cellspacing=0>
|
||||
<tr><td class="right"><label for="keyinput">Unique key</label></td><td><input type="text" name="key" id="keyinput" autocomplete="off" pattern="...." placeholder="––––" required style="text-transform: uppercase;" maxlength=4/></td></tr>
|
||||
<tr><td class="right"><label for="fileinput">EPUB/MOBI file</label></td><td><input type="file" name="file" id="fileinput" accept=".epub,.mobi,.pdf,.cbz,.cbr,application/epub+zip,application/x-mobipocket-ebook,application/pdf,application/vnd.comicbook+zip,application/vnd.comicbook-rar" required /></td></tr>
|
||||
<tr><td class="right"><label for="fileinput">EPUB/MOBI file</label></td><td><input type="file" name="file" id="fileinput" accept=".txt,.epub,.mobi,.pdf,.cbz,.cbr,application/epub+zip,application/x-mobipocket-ebook,application/pdf,application/vnd.comicbook+zip,application/vnd.comicbook-rar" required /></td></tr>
|
||||
<tr><td></td><td id="fileinfo"></td></tr>
|
||||
<tr><td class="right"><label for="kepubify">Kepubify</label></td><td><input type="checkbox" name="kepubify" id="kepubify" checked /></td></tr>
|
||||
<tr><td></td><td><input type="submit" value="Upload and send" /></td></tr>
|
||||
@@ -33,30 +33,36 @@
|
||||
Source code on <a href="https://github.com/daniel-j/send2ereader" target="_blank">Github</a> - <a id="siteurl">https://send.djazz.se</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function getCookies() {
|
||||
var cookieRegex = /([\w\.]+)\s*=\s*(?:"((?:\\"|[^"])*)"|(.*?))\s*(?:[;,]|$)/g
|
||||
var cookies = {}
|
||||
var match
|
||||
while( (match = cookieRegex.exec(document.cookie)) !== null ) {
|
||||
var value = match[2] || match[3]
|
||||
cookies[match[1]] = decodeURIComponent(value)
|
||||
try {
|
||||
cookies[match[1]] = JSON.parse(cookies[match[1]])
|
||||
} catch (err) {}
|
||||
}
|
||||
return cookies
|
||||
var cookieRegex = /([\w\.]+)\s*=\s*(?:"((?:\\"|[^"])*)"|(.*?))\s*(?:[;,]|$)/g
|
||||
var cookies = {}
|
||||
var match
|
||||
while( (match = cookieRegex.exec(document.cookie)) !== null ) {
|
||||
var value = match[2] || match[3]
|
||||
cookies[match[1]] = decodeURIComponent(value)
|
||||
try {
|
||||
cookies[match[1]] = JSON.parse(cookies[match[1]])
|
||||
} catch (err) {}
|
||||
}
|
||||
return cookies
|
||||
}
|
||||
function deleteCookie(name) {
|
||||
document.cookie = name + "= ; expires = Thu, 01 Jan 1970 00:00:00 GMT"
|
||||
}
|
||||
|
||||
|
||||
var uploadstatus = document.getElementById('uploadstatus')
|
||||
var keyinput = document.getElementById('keyinput')
|
||||
var fileinput = document.getElementById('fileinput')
|
||||
var fileinputAccept = fileinput.accept.split(',') // cache it
|
||||
var fileinfo = document.getElementById('fileinfo')
|
||||
var siteurl = document.getElementById('siteurl')
|
||||
|
||||
|
||||
var isIOS = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
|
||||
|
||||
var flash = getCookies().flash
|
||||
deleteCookie('flash')
|
||||
|
||||
@@ -80,20 +86,53 @@ uploadstatus.addEventListener('click', function () {
|
||||
uploadstatus.className = ''
|
||||
}, 500)
|
||||
}, false)
|
||||
|
||||
function fileinputChange () {
|
||||
if (!fileinput.files[0]) {
|
||||
if (!fileinput.files[0] || fileinput.files.length === 0) {
|
||||
fileinfo.textContent = ''
|
||||
fileinput.value = ''
|
||||
return
|
||||
}
|
||||
|
||||
if (fileinput.accept == '') {
|
||||
var filename = fileinput.files[0].name
|
||||
var type = fileinput.files[0].type
|
||||
var found = false
|
||||
for (var i = 0; i < fileinputAccept.length; i++) {
|
||||
var item = fileinputAccept[i]
|
||||
if (item.length > 1 && item[0] == '.') {
|
||||
if (filename.toLowerCase().endsWith(item.toLowerCase())) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
} else if (type == item) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
fileinfo.textContent = ''
|
||||
fileinput.value = ''
|
||||
alert("Invalid file: " + filename)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fileinfo.textContent = Math.ceil(fileinput.files[0].size / 1024) + ' kB'
|
||||
}
|
||||
fileinput.addEventListener('change', fileinputChange, false)
|
||||
fileinputChange()
|
||||
|
||||
siteurl.textContent = window.location.href
|
||||
if (isIOS) {
|
||||
// Can't accept .mobi files otherwise (iOS thinks it's an unknown type)
|
||||
fileinput.accept = ''
|
||||
}
|
||||
|
||||
siteurl.textContent = window.location.origin
|
||||
siteurl.href = siteurl.textContent
|
||||
siteurl.target = '_self'
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user