Reader: allow loading files from URL parameter

Fixes #3
This commit is contained in:
John Factotum
2023-03-15 11:00:21 +08:00
parent c7a4f5ef46
commit 514cb81fe6
2 changed files with 10 additions and 1 deletions
+8
View File
@@ -320,3 +320,11 @@ dropTarget.addEventListener('dragover', dragOverHandler)
$('#file-input').addEventListener('change', e =>
open(e.target.files[0]).catch(e => console.error(e)))
$('#file-button').addEventListener('click', () => $('#file-input').click())
const params = new URLSearchParams(location.search)
const url = params.get('url')
if (url) fetch(url)
.then(res => res.blob())
.then(blob => open(new File([blob], new URL(url).pathname)))
.catch(e => console.error(e))
else dropTarget.style.visibility = 'visible'