diff --git a/src/pyj/dom.pyj b/src/pyj/dom.pyj index f88ba5da3c..7911d16f90 100644 --- a/src/pyj/dom.pyj +++ b/src/pyj/dom.pyj @@ -78,3 +78,9 @@ def svgicon(name, height, width): u.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#icon-' + name) ans.appendChild(u) return ans + +def element(elem_id, child_selector): + ans = document.getElementById(elem_id) if elem_id else document.body + if child_selector: + ans = ans.querySelector(child_selector) + return ans diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 169afcd475..7ee72a6599 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -2,7 +2,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal from __python__ import hash_literals, bound_methods -from dom import clear, set_css +from dom import clear, set_css, element from elementmaker import E from book_list.theme import get_color from widgets import create_spinner @@ -44,13 +44,13 @@ class MainOverlay: # {{{ set_css(E.div( onclick=def (evt):evt.stopPropagation();, E.div(self.overlay.view.book.metadata.title, style='max-width: 90%; text-overflow: ellipsis'), - E.div(self.date_formatter.format(Date()), style='max-width: 9%; text-overflow: ellipsis'), + E.div(self.date_formatter.format(Date()), data_time='1', style='max-width: 9%; text-overflow: ellipsis'), ), display='flex', justify_content='space-between', align_items='baseline', font_size='smaller', padding='0.5ex 1rem', border_bottom='solid 1px currentColor') ), background_color=get_color('window-background'))) self.timer = setInterval(self.update_time, 1000) def update_time(self): - document.getElementById(self.container_id).firstChild.firstChild.lastChild.textContent = self.date_formatter.format(Date()) + element(self.container_id, '[data-time]').textContent = self.date_formatter.format(Date()) def on_hide(self): clearInterval(self.timer)