From 54c6c6e3d72363205c21a8b7d1f40932896f94b2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 6 Jan 2021 15:09:49 +0530 Subject: [PATCH] Add a download button to the export highlights dialog --- src/pyj/read_book/highlights.pyj | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/highlights.pyj b/src/pyj/read_book/highlights.pyj index 45def397ef..456db6574f 100644 --- a/src/pyj/read_book/highlights.pyj +++ b/src/pyj/read_book/highlights.pyj @@ -604,7 +604,25 @@ def show_export_dialog(annotations_manager): x.focus() x.select() document.execCommand('copy') - )) + ), + '\xa0', + create_button(_('Download'), 'cloud-download', def (ev): + nonlocal fmt + text = document.getElementById(ta_id).textContent + ext = 'md' if fmt is 'markdown' else ('txt' if fmt is 'text' else 'json') + mt = 'text/markdown' if fmt is 'markdown' else ('text/plain' if fmt is 'text' else 'application/json') + filename = f'highlights.{ext}' + file = new Blob([text], {'type': mt}) + url = window.URL.createObjectURL(file) + a = E.a(href=url, download=filename) + document.body.appendChild(a) + a.click() + window.setTimeout(def(): + document.body.removeChild(a) + window.URL.revokeObjectURL(url) + , 0) + ), + ) )) window.setTimeout(update_text, 0) )