Only update stylesheet if it's overridden per-domain
This commit is contained in:
parent
4f665784f2
commit
6a00877a71
@ -25,7 +25,7 @@ import netrc
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.config import config, configutils
|
||||
from qutebrowser.utils import usertypes, message, log, objreg, jinja, utils
|
||||
from qutebrowser.mainwindow import mainwindow
|
||||
|
||||
@ -274,9 +274,16 @@ def get_tab(win_id, target):
|
||||
|
||||
|
||||
def get_user_stylesheet(url=None):
|
||||
"""Get the combined user-stylesheet."""
|
||||
"""Get the combined user-stylesheet.
|
||||
|
||||
If `url` is given and there's no overridden stylesheet, return
|
||||
`configutils.UNSET`.
|
||||
"""
|
||||
css = ''
|
||||
stylesheets = config.instance.get("content.user_stylesheets", url)
|
||||
stylesheets = config.instance.get("content.user_stylesheets", url,
|
||||
fallback=url is None)
|
||||
if stylesheets is configutils.UNSET:
|
||||
return stylesheets
|
||||
|
||||
for filename in stylesheets:
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
|
@ -32,7 +32,7 @@ from PyQt5.QtNetwork import QAuthenticator
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineScript
|
||||
|
||||
from qutebrowser.config import configdata, config
|
||||
from qutebrowser.config import configdata, config, configutils
|
||||
from qutebrowser.browser import browsertab, mouse, shared
|
||||
from qutebrowser.browser.webengine import (webview, webengineelem, tabhistory,
|
||||
interceptor, webenginequtescheme,
|
||||
@ -796,7 +796,7 @@ class _WebEngineScripts(QObject):
|
||||
@pyqtSlot(str)
|
||||
def _on_config_changed(self, option):
|
||||
if option in ['scrolling.bar', 'content.user_stylesheets']:
|
||||
self._update_stylesheet(url=self._tab.url())
|
||||
self._update_stylesheet(url=self._tab.url(), force=True)
|
||||
|
||||
@pyqtSlot()
|
||||
def _on_load_finished(self):
|
||||
@ -804,11 +804,20 @@ class _WebEngineScripts(QObject):
|
||||
self._update_stylesheet(url)
|
||||
|
||||
@pyqtSlot(QUrl)
|
||||
def _update_stylesheet(self, url):
|
||||
"""Update the custom stylesheet in existing tabs."""
|
||||
def _update_stylesheet(self, url, force=False):
|
||||
"""Update the custom stylesheet in existing tabs.
|
||||
|
||||
Arguments:
|
||||
url: The url to get the stylesheet for.
|
||||
force: Also update the global stylesheet.
|
||||
"""
|
||||
css = shared.get_user_stylesheet(url=url)
|
||||
code = javascript.assemble('stylesheet', 'set_css', css)
|
||||
self._tab.run_js_async(code)
|
||||
if css is configutils.UNSET and force:
|
||||
css = shared.get_user_stylesheet(url=None)
|
||||
|
||||
if css is not configutils.UNSET:
|
||||
code = javascript.assemble('stylesheet', 'set_css', css)
|
||||
self._tab.run_js_async(code)
|
||||
|
||||
def _inject_early_js(self, name, js_code, *,
|
||||
world=QWebEngineScript.ApplicationWorld,
|
||||
|
Loading…
Reference in New Issue
Block a user