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
|
||||
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:
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue