Load lookup JS at document creation

This commit is contained in:
Kovid Goyal 2020-04-16 09:28:30 +05:30
parent 42541ba212
commit d0c5d21661
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 3 deletions

View File

@ -29,5 +29,7 @@
if (promo) promo.parentNode.removeChild(promo); 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);
}
})(); })();

View File

@ -14,7 +14,7 @@ from PyQt5.Qt import (
QTimer, QUrl, QVBoxLayout, QWidget, pyqtSignal QTimer, QUrl, QVBoxLayout, QWidget, pyqtSignal
) )
from PyQt5.QtWebEngineWidgets import ( from PyQt5.QtWebEngineWidgets import (
QWebEnginePage, QWebEngineProfile, QWebEngineView QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineView
) )
from calibre import prints, random_user_agent from calibre import prints, random_user_agent
@ -193,7 +193,7 @@ def create_profile():
ans.setHttpUserAgent(random_user_agent(allow_ie=False)) ans.setHttpUserAgent(random_user_agent(allow_ie=False))
ans.setCachePath(os.path.join(cache_dir(), 'ev2vl')) ans.setCachePath(os.path.join(cache_dir(), 'ev2vl'))
js = P('lookup.js', data=True, allow_user_override=False) 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 = ans.settings()
s.setDefaultTextEncoding('utf-8') s.setDefaultTextEncoding('utf-8')
create_profile.ans = ans create_profile.ans = ans