Add per-domain user stylesheet support

This commit is contained in:
Jordyn/The Linux Geek 2018-04-18 15:42:15 -05:00 committed by Florian Bruhin
parent a0adee55c9
commit f391d726c0
3 changed files with 12 additions and 7 deletions

View File

@ -273,10 +273,10 @@ def get_tab(win_id, target):
return tabbed_browser.tabopen(url=None, background=bg_tab) return tabbed_browser.tabopen(url=None, background=bg_tab)
def get_user_stylesheet(): def get_user_stylesheet(url=None):
"""Get the combined user-stylesheet.""" """Get the combined user-stylesheet."""
css = '' css = ''
stylesheets = config.val.content.user_stylesheets stylesheets = config.instance.get("content.user_stylesheets", url)
for filename in stylesheets: for filename in stylesheets:
with open(filename, 'r', encoding='utf-8') as f: with open(filename, 'r', encoding='utf-8') as f:

View File

@ -18,7 +18,6 @@
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Wrapper over a QWebEngineView.""" """Wrapper over a QWebEngineView."""
import math import math
import functools import functools
import sys import sys
@ -796,11 +795,12 @@ class _WebEngineScripts(QObject):
def _on_config_changed(self, option): def _on_config_changed(self, option):
if option in ['scrolling.bar', 'content.user_stylesheets']: if option in ['scrolling.bar', 'content.user_stylesheets']:
self._init_stylesheet() 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.""" """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) code = javascript.assemble('stylesheet', 'set_css', css)
self._tab.run_js_async(code) self._tab.run_js_async(code)
@ -863,8 +863,9 @@ class _WebEngineScripts(QObject):
Partially inspired by QupZilla: Partially inspired by QupZilla:
https://github.com/QupZilla/qupzilla/blob/v2.0/src/lib/app/mainapplication.cpp#L1063-L1101 https://github.com/QupZilla/qupzilla/blob/v2.0/src/lib/app/mainapplication.cpp#L1063-L1101
""" """
self._remove_early_js('stylesheet') self._remove_early_js('stylesheet')
css = shared.get_user_stylesheet() css = shared.get_user_stylesheet(url=None)
js_code = javascript.wrap_global( js_code = javascript.wrap_global(
'stylesheet', 'stylesheet',
utils.read_file('javascript/stylesheet.js'), utils.read_file('javascript/stylesheet.js'),
@ -1225,6 +1226,9 @@ class WebEngineTab(browsertab.AbstractTab):
# the old icon is still displayed. # the old icon is still displayed.
self.icon_changed.emit(QIcon()) self.icon_changed.emit(QIcon())
url = self.url(requested=True)
self._update_stylesheet(url)
@pyqtSlot(QUrl) @pyqtSlot(QUrl)
def _on_predicted_navigation(self, url): def _on_predicted_navigation(self, url):
"""If we know we're going to visit an URL soon, change the settings. """If we know we're going to visit an URL soon, change the settings.

View File

@ -689,6 +689,7 @@ content.user_stylesheets:
valtype: File valtype: File
none_ok: True none_ok: True
default: [] default: []
supports_pattern: true
desc: List of user stylesheet filenames to use. desc: List of user stylesheet filenames to use.
content.webgl: content.webgl: