mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Move dark mode script generation into own function
This commit is contained in:
parent
a4672db7bc
commit
26b8d40b12
@ -235,23 +235,9 @@ def uniq(vals):
|
||||
return tuple(x for x in vals if x not in seen and not seen_add(x))
|
||||
|
||||
|
||||
def create_profile():
|
||||
ans = getattr(create_profile, 'ans', None)
|
||||
if ans is None:
|
||||
ans = QWebEngineProfile(QApplication.instance())
|
||||
ua = 'calibre-editor-preview ' + __version__
|
||||
ans.setHttpUserAgent(ua)
|
||||
if is_running_from_develop:
|
||||
from calibre.utils.rapydscript import compile_editor
|
||||
compile_editor()
|
||||
js = P('editor.js', data=True, allow_user_override=False)
|
||||
cparser = P('csscolorparser.js', data=True, allow_user_override=False)
|
||||
def create_dark_mode_script():
|
||||
dark_mode_css = P('dark_mode.css', data=True, allow_user_override=False).decode('utf-8')
|
||||
|
||||
insert_scripts(ans,
|
||||
create_script('csscolorparser.js', cparser),
|
||||
create_script('editor.js', js),
|
||||
create_script('dark-mode.js', '''
|
||||
return create_script('dark-mode.js', '''
|
||||
(function() {
|
||||
var settings = JSON.parse(navigator.userAgent.split('|')[1]);
|
||||
var dark_css = CSS;
|
||||
@ -282,6 +268,24 @@ def create_profile():
|
||||
})();
|
||||
'''.replace('CSS', json.dumps(dark_mode_css), 1),
|
||||
injection_point=QWebEngineScript.InjectionPoint.DocumentCreation)
|
||||
|
||||
|
||||
def create_profile():
|
||||
ans = getattr(create_profile, 'ans', None)
|
||||
if ans is None:
|
||||
ans = QWebEngineProfile(QApplication.instance())
|
||||
ua = 'calibre-editor-preview ' + __version__
|
||||
ans.setHttpUserAgent(ua)
|
||||
if is_running_from_develop:
|
||||
from calibre.utils.rapydscript import compile_editor
|
||||
compile_editor()
|
||||
js = P('editor.js', data=True, allow_user_override=False)
|
||||
cparser = P('csscolorparser.js', data=True, allow_user_override=False)
|
||||
|
||||
insert_scripts(ans,
|
||||
create_script('csscolorparser.js', cparser),
|
||||
create_script('editor.js', js),
|
||||
create_dark_mode_script(),
|
||||
)
|
||||
url_handler = UrlSchemeHandler(ans)
|
||||
ans.installUrlSchemeHandler(QByteArray(FAKE_PROTOCOL.encode('ascii')), url_handler)
|
||||
|
Loading…
x
Reference in New Issue
Block a user