async function loadDocument(id, args) { var data = window.data = {} var parts = id.split('/') data.id = parts.shift() data.site = pandora.hostname if (parts.length == 2) { data.page = parts.shift() } if (parts.length == 1) { var rect = parts[0].split(',') if (rect.length == 1) { data.page = parts[0] } else { data.crop = rect } } else if (parts.length == 2) { } var response = await pandoraAPI('getDocument', { id: data.id, keys: [ "id", "title", "extension", "text", ] }) if (response.status.code != 200) { return { site: data.site, error: response.status } } data.document = response['data'] data.title = data.document.name data.link = `${pandora.proto}://${data.site}/documents/${data.document.id}` return data } async function renderDocument(data) { if (data.error) { return renderError(data) } div = document.createElement('div') div.className = "content" if (!data.document) { div.innerHTML = `
document not found
` } else if (data.document.extension == "html") { div.innerHTML = `

${data.document.title}

${data.document.text}
Open on ${data.site}
` div.querySelectorAll('.text a').forEach(a => { a.addEventListener("click", clickLink) }) } else if (data.document.extension == "pdf" && data.page && data.crop) { var img = `${pandora.proto}://${data.site}/documents/${data.document.id}/1024p${data.page},${data.crop.join(',')}.jpg` data.link = getLink(`documents/${data.document.id}/${data.page}`) div.innerHTML = `

${data.document.title}

Open pdf page
` } else if (data.document.extension == "pdf") { var page = data.page || 1, file = encodeURIComponent(`/documents/${data.document.id}/${safeDocumentName(data.document.title)}.pdf`) div.innerHTML = `

${data.document.title}

Open on ${data.site}
` } else if (data.document.extension == "jpg" || data.document.extension == "png") { var img = `${pandora.proto}://${data.site}/documents/${data.document.id}/${safeDocumentName(data.document.title)}.${data.document.extension}` var open_text = `Open on ${data.site}` if (data.crop) { img = `${pandora.proto}://${data.site}/documents/${data.document.id}/1024p${data.crop.join(',')}.jpg` data.link = getLink(`documents/${data.document.id}`) open_text = `Open image` } div.innerHTML = `

${data.document.title}

${open_text}
` } else { div.innerHTML = `unsupported document type` } document.querySelector(".content").replaceWith(div) }