diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 0b193ba26e..6e82350692 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -370,7 +370,22 @@ class MainOverlay: # {{{ def(): self.overlay.hide(), ui_operations.quit();, 'remove'), )) else: - pass + copy_actions = E.ul() + if self.elements.link: + copy_actions.appendChild(ac(_('Copy link'), _('Copy the current link'), def(): + self.overlay.hide(), ui_operations.copy_selection(self.elements.link) + , 'link')) + if self.elements.img: + copy_actions.appendChild(ac(_('View image'), _('View the current image'), def(): + self.overlay.hide(), ui_operations.view_image(self.elements.img) + , 'image')) + if window.navigator.clipboard: + copy_actions.appendChild(ac(_('Copy image'), _('Copy the current image'), def(): + self.overlay.hide(), ui_operations.copy_image(self.elements.img) + , 'copy')) + if copy_actions.childNodes.length: + actions_div.appendChild(copy_actions) + container.appendChild(set_css(E.div(class_=MAIN_OVERLAY_TS_CLASS, # top section onclick=def (evt):evt.stopPropagation();, diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index ad0a196cdf..d646bc5d80 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -81,6 +81,8 @@ class ReadUI: ui_operations.stop_waiting_for_messages_from = self.stop_waiting_for_messages_from.bind(self) ui_operations.update_metadata = self.update_metadata.bind(self) ui_operations.close_book = self.close_book.bind(self) + ui_operations.copy_image = self.copy_image.bind(self) + ui_operations.view_image = self.view_image.bind(self) ui_operations.open_url = def(url): window.open(url, '_blank') ui_operations.copy_selection = def(text, html): @@ -187,6 +189,26 @@ class ReadUI: def close_book(self): self.base_url_data = {} + def copy_image(self, image_file_name): + if not self.view?.book: + return + ui_operations.get_file( + self.view.book, image_file_name, def(blob, name, mimetype): + try: + window.navigator.clipboard.write([new ClipboardItem({mimetype: blob})]) # noqa + except Exception as err: + error_dialog(_('Could not copy image'), str(err)) + ) + + def view_image(self, image_file_name): + if not self.view?.book: + return + ui_operations.get_file( + self.view.book, image_file_name, def(blob, name, mimetype): + url = window.URL.createObjectURL(blob) + window.open(url) + ) + def load_book(self, library_id, book_id, fmt, metadata, force_reload): self.base_url_data = {'library_id': library_id, 'book_id':book_id, 'fmt':fmt} if not self.db.initialized: