From d0c5d216613b58a56dc26bc9016420dce223267f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Apr 2020 09:28:30 +0530 Subject: [PATCH] Load lookup JS at document creation --- resources/lookup.js | 4 +++- src/calibre/gui2/viewer/lookup.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/lookup.js b/resources/lookup.js index abccda57c3..693bfa7da2 100644 --- a/resources/lookup.js +++ b/resources/lookup.js @@ -29,5 +29,7 @@ if (promo) promo.parentNode.removeChild(promo); } - if (window.location.hostname === 'www.google.com') fix_google_markup(); + if (window.location.hostname === 'www.google.com') { + window.addEventListener('DOMContentLoaded', fix_google_markup); + } })(); diff --git a/src/calibre/gui2/viewer/lookup.py b/src/calibre/gui2/viewer/lookup.py index 42e5a7112c..699d4b3972 100644 --- a/src/calibre/gui2/viewer/lookup.py +++ b/src/calibre/gui2/viewer/lookup.py @@ -14,7 +14,7 @@ from PyQt5.Qt import ( QTimer, QUrl, QVBoxLayout, QWidget, pyqtSignal ) from PyQt5.QtWebEngineWidgets import ( - QWebEnginePage, QWebEngineProfile, QWebEngineView + QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineView ) from calibre import prints, random_user_agent @@ -193,7 +193,7 @@ def create_profile(): ans.setHttpUserAgent(random_user_agent(allow_ie=False)) ans.setCachePath(os.path.join(cache_dir(), 'ev2vl')) js = P('lookup.js', data=True, allow_user_override=False) - insert_scripts(ans, create_script('lookup.js', js)) + insert_scripts(ans, create_script('lookup.js', js, injection_point=QWebEngineScript.DocumentCreation)) s = ans.settings() s.setDefaultTextEncoding('utf-8') create_profile.ans = ans