Add per-domain user stylesheet support
This commit is contained in:
parent
a0adee55c9
commit
f391d726c0
@ -273,10 +273,10 @@ def get_tab(win_id, target):
|
||||
return tabbed_browser.tabopen(url=None, background=bg_tab)
|
||||
|
||||
|
||||
def get_user_stylesheet():
|
||||
def get_user_stylesheet(url=None):
|
||||
"""Get the combined user-stylesheet."""
|
||||
css = ''
|
||||
stylesheets = config.val.content.user_stylesheets
|
||||
stylesheets = config.instance.get("content.user_stylesheets", url)
|
||||
|
||||
for filename in stylesheets:
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
|
@ -18,7 +18,6 @@
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Wrapper over a QWebEngineView."""
|
||||
|
||||
import math
|
||||
import functools
|
||||
import sys
|
||||
@ -796,11 +795,12 @@ class _WebEngineScripts(QObject):
|
||||
def _on_config_changed(self, option):
|
||||
if option in ['scrolling.bar', 'content.user_stylesheets']:
|
||||
self._init_stylesheet()
|
||||
self._update_stylesheet()
|
||||
url = self.url(requested=True)
|
||||
self._update_stylesheet(url=url)
|
||||
|
||||
def _update_stylesheet(self):
|
||||
def _update_stylesheet(self, url=None):
|
||||
"""Update the custom stylesheet in existing tabs."""
|
||||
css = shared.get_user_stylesheet()
|
||||
css = shared.get_user_stylesheet(url=url)
|
||||
code = javascript.assemble('stylesheet', 'set_css', css)
|
||||
self._tab.run_js_async(code)
|
||||
|
||||
@ -863,8 +863,9 @@ class _WebEngineScripts(QObject):
|
||||
Partially inspired by QupZilla:
|
||||
https://github.com/QupZilla/qupzilla/blob/v2.0/src/lib/app/mainapplication.cpp#L1063-L1101
|
||||
"""
|
||||
|
||||
self._remove_early_js('stylesheet')
|
||||
css = shared.get_user_stylesheet()
|
||||
css = shared.get_user_stylesheet(url=None)
|
||||
js_code = javascript.wrap_global(
|
||||
'stylesheet',
|
||||
utils.read_file('javascript/stylesheet.js'),
|
||||
@ -1225,6 +1226,9 @@ class WebEngineTab(browsertab.AbstractTab):
|
||||
# the old icon is still displayed.
|
||||
self.icon_changed.emit(QIcon())
|
||||
|
||||
url = self.url(requested=True)
|
||||
self._update_stylesheet(url)
|
||||
|
||||
@pyqtSlot(QUrl)
|
||||
def _on_predicted_navigation(self, url):
|
||||
"""If we know we're going to visit an URL soon, change the settings.
|
||||
|
@ -689,6 +689,7 @@ content.user_stylesheets:
|
||||
valtype: File
|
||||
none_ok: True
|
||||
default: []
|
||||
supports_pattern: true
|
||||
desc: List of user stylesheet filenames to use.
|
||||
|
||||
content.webgl:
|
||||
|
Loading…
Reference in New Issue
Block a user