mirror of https://github.com/gorhill/uBlock.git
Propagate upward accent color stylesheet only when it changes
This commit is contained in:
parent
3b350cc844
commit
c65f896a2a
|
@ -212,13 +212,14 @@ const changeUserSettings = function(name, value) {
|
||||||
// Maybe reflect some changes immediately
|
// Maybe reflect some changes immediately
|
||||||
switch ( name ) {
|
switch ( name ) {
|
||||||
case 'uiTheme':
|
case 'uiTheme':
|
||||||
uDom.setTheme(value, [ 'dark', 'light' ]);
|
uDom.setTheme(value, true);
|
||||||
break;
|
break;
|
||||||
case 'uiAccentCustom':
|
case 'uiAccentCustom':
|
||||||
case 'uiAccentCustom0':
|
case 'uiAccentCustom0':
|
||||||
uDom.setAccentColor(
|
uDom.setAccentColor(
|
||||||
uDom.nodeFromSelector('[data-setting-name="uiAccentCustom"]').checked,
|
uDom.nodeFromSelector('[data-setting-name="uiAccentCustom"]').checked,
|
||||||
uDom.nodeFromSelector('[data-setting-name="uiAccentCustom0"]').value
|
uDom.nodeFromSelector('[data-setting-name="uiAccentCustom0"]').value,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -71,7 +71,7 @@ DOMListFactory.root = document.querySelector(':root');
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
DOMListFactory.setTheme = function(theme) {
|
DOMListFactory.setTheme = function(theme, propagate = false) {
|
||||||
if ( theme === 'auto' ) {
|
if ( theme === 'auto' ) {
|
||||||
if ( typeof self.matchMedia === 'function' ) {
|
if ( typeof self.matchMedia === 'function' ) {
|
||||||
const mql = self.matchMedia('(prefers-color-scheme: dark)');
|
const mql = self.matchMedia('(prefers-color-scheme: dark)');
|
||||||
|
@ -92,13 +92,19 @@ DOMListFactory.setTheme = function(theme) {
|
||||||
rootcl.add('light');
|
rootcl.add('light');
|
||||||
rootcl.remove('dark');
|
rootcl.remove('dark');
|
||||||
}
|
}
|
||||||
|
if ( propagate === false ) { break; }
|
||||||
if ( w === w.parent ) { break; }
|
if ( w === w.parent ) { break; }
|
||||||
w = w.parent;
|
w = w.parent;
|
||||||
try { void w.document; } catch(ex) { return; }
|
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 ) {
|
if ( accentEnabled && stylesheet === '' && self.hsluv !== undefined ) {
|
||||||
const toRGB = hsl => self.hsluv.hsluvToRgb(hsl).map(a => Math.round(a * 255)).join(' ');
|
const toRGB = hsl => self.hsluv.hsluvToRgb(hsl).map(a => Math.round(a * 255)).join(' ');
|
||||||
// Normalize first
|
// Normalize first
|
||||||
|
@ -145,6 +151,7 @@ DOMListFactory.setAccentColor = function(accentEnabled, accentColor, stylesheet
|
||||||
} else {
|
} else {
|
||||||
wdoc.documentElement.classList.remove('accented');
|
wdoc.documentElement.classList.remove('accented');
|
||||||
}
|
}
|
||||||
|
if ( propagate === false ) { break; }
|
||||||
if ( w === w.parent ) { break; }
|
if ( w === w.parent ) { break; }
|
||||||
w = w.parent;
|
w = w.parent;
|
||||||
try { void w.document; } catch(ex) { break; }
|
try { void w.document; } catch(ex) { break; }
|
||||||
|
@ -161,6 +168,7 @@ DOMListFactory.setAccentColor = function(accentEnabled, accentColor, stylesheet
|
||||||
uDom.setAccentColor(
|
uDom.setAccentColor(
|
||||||
true,
|
true,
|
||||||
response.uiAccentCustom0,
|
response.uiAccentCustom0,
|
||||||
|
false,
|
||||||
response.uiAccentStylesheet
|
response.uiAccentStylesheet
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue