1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

Propagate upward accent color stylesheet only when it changes

This commit is contained in:
Raymond Hill 2022-02-03 09:34:33 -05:00
parent 3b350cc844
commit c65f896a2a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 13 additions and 4 deletions

View File

@ -212,13 +212,14 @@ const changeUserSettings = function(name, value) {
// Maybe reflect some changes immediately
switch ( name ) {
case 'uiTheme':
uDom.setTheme(value, [ 'dark', 'light' ]);
uDom.setTheme(value, true);
break;
case 'uiAccentCustom':
case 'uiAccentCustom0':
uDom.setAccentColor(
uDom.nodeFromSelector('[data-setting-name="uiAccentCustom"]').checked,
uDom.nodeFromSelector('[data-setting-name="uiAccentCustom0"]').value
uDom.nodeFromSelector('[data-setting-name="uiAccentCustom0"]').value,
true
);
break;
default:

View File

@ -71,7 +71,7 @@ DOMListFactory.root = document.querySelector(':root');
/******************************************************************************/
DOMListFactory.setTheme = function(theme) {
DOMListFactory.setTheme = function(theme, propagate = false) {
if ( theme === 'auto' ) {
if ( typeof self.matchMedia === 'function' ) {
const mql = self.matchMedia('(prefers-color-scheme: dark)');
@ -92,13 +92,19 @@ DOMListFactory.setTheme = function(theme) {
rootcl.add('light');
rootcl.remove('dark');
}
if ( propagate === false ) { break; }
if ( w === w.parent ) { break; }
w = w.parent;
try { void w.document; } catch(ex) { return; }
}
};
DOMListFactory.setAccentColor = function(accentEnabled, accentColor, stylesheet = '') {
DOMListFactory.setAccentColor = function(
accentEnabled,
accentColor,
propagate,
stylesheet = ''
) {
if ( accentEnabled && stylesheet === '' && self.hsluv !== undefined ) {
const toRGB = hsl => self.hsluv.hsluvToRgb(hsl).map(a => Math.round(a * 255)).join(' ');
// Normalize first
@ -145,6 +151,7 @@ DOMListFactory.setAccentColor = function(accentEnabled, accentColor, stylesheet
} else {
wdoc.documentElement.classList.remove('accented');
}
if ( propagate === false ) { break; }
if ( w === w.parent ) { break; }
w = w.parent;
try { void w.document; } catch(ex) { break; }
@ -161,6 +168,7 @@ DOMListFactory.setAccentColor = function(accentEnabled, accentColor, stylesheet
uDom.setAccentColor(
true,
response.uiAccentCustom0,
false,
response.uiAccentStylesheet
);
}