Skip to content

Commit e3a6d84

Browse files
committed
Add advanced setting to force a light/dark theme
Related feedback: - uBlockOrigin/uBlock-issues#401 (comment) Name: `uiTheme` Default: `unset` Values: - `unset`: uBO will pick the theme according to browser's `prefers-color-scheme` - `light`: force light scheme - `dark`: force dark theme This advanced setting is not to be documented yet as it has not been decided this is a long term solution.
1 parent b179dc0 commit e3a6d84

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

src/css/logger-ui-inspector.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
padding-left: 0.5em;
1515
}
1616
#domInspector ul {
17-
background-color: #fff;
17+
background-color: var(--default-surface);
1818
margin: 0;
1919
padding-left: 1em;
2020
}
@@ -37,7 +37,7 @@
3737
color: #aaa;
3838
}
3939
#domInspector li > span:first-child {
40-
color: #000;
40+
color: var(--default-ink);
4141
cursor: default;
4242
font-size: 1rem;
4343
margin-right: 0;

src/css/logger-ui.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ textarea {
1212
width: 100%;
1313
}
1414
.permatoolbar {
15-
background-color: white;
15+
background-color: var(--default-surface);
1616
border: 0;
1717
box-sizing: border-box;
1818
display: flex;
@@ -34,7 +34,7 @@ textarea {
3434
fill: #5F9EA0;
3535
}
3636
.permatoolbar .button:hover {
37-
background-color: #eee;
37+
background-color: var(--default-surface-hover);
3838
}
3939
#pageSelector {
4040
min-width: 10em;
@@ -135,7 +135,7 @@ body[dir="rtl"] #pageSelector {
135135
transform: scaleY(1);
136136
}
137137
#netInspector #filterExprPicker {
138-
background-color: white;
138+
background-color: var(--default-surface);
139139
border: 1px solid gray;
140140
display: none;
141141
position: absolute;
@@ -445,7 +445,7 @@ body.colorBlind #netFilteringDialog > .panes > .details > div[data-status="2"] b
445445
}
446446

447447
#popupContainer {
448-
background: white;
448+
background-color: var(--default-surface);
449449
border: 1px solid gray;
450450
bottom: 0;
451451
display: none;
@@ -481,7 +481,7 @@ body.colorBlind #netFilteringDialog > .panes > .details > div[data-status="2"] b
481481
position: relative;
482482
}
483483
#modalOverlay > div > div:nth-of-type(1) {
484-
background-color: white;
484+
background-color: var(--default-surface);
485485
border: 0;
486486
box-sizing: border-box;
487487
padding: 1em;
@@ -490,13 +490,13 @@ body.colorBlind #netFilteringDialog > .panes > .details > div[data-status="2"] b
490490
width: 90vw;
491491
}
492492
#modalOverlay > div > div:nth-of-type(2) {
493-
stroke: #000;
493+
stroke: var(--default-ink);
494494
stroke-width: 3px;
495495
position: absolute;
496496
width: 1.6em;
497497
height: 1.6em;
498498
bottom: calc(100% + 2px);
499-
background-color: white;
499+
background-color: var(--default-surface);
500500
}
501501
body[dir="ltr"] #modalOverlay > div > div:nth-of-type(2) {
502502
right: 0;
@@ -505,7 +505,7 @@ body[dir="rtl"] #modalOverlay > div > div:nth-of-type(2) {
505505
left: 0;
506506
}
507507
#modalOverlay > div > div:nth-of-type(2):hover {
508-
background-color: #eee;
508+
background-color: var(--default-surface-hover);
509509
}
510510
#modalOverlay > div > div:nth-of-type(2) > * {
511511
pointer-events: none;

src/js/background.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const µBlock = (( ) => { // jshint ignore:line
7777
uiPopupConfig: 'undocumented',
7878
uiFlavor: 'unset',
7979
uiStyles: 'unset',
80+
uiTheme: 'unset',
8081
updateAssetBypassBrowserCache: false,
8182
userResourcesLocation: 'unset',
8283
};

src/js/messaging.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ const onMessage = function(request, sender, callback) {
160160
break;
161161

162162
case 'uiStyles':
163-
response = µb.hiddenSettings.uiStyles;
163+
response = {
164+
uiStyles: µb.hiddenSettings.uiStyles,
165+
uiTheme: µb.hiddenSettings.uiTheme,
166+
};
164167
break;
165168

166169
case 'userSettings':

src/js/udom.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ DOMListFactory.nodeFromSelector = function(selector) {
9393
/******************************************************************************/
9494

9595
{
96+
// https://github.com/uBlockOrigin/uBlock-issues/issues/1044
97+
// Offer the possibility to bypass uBO's default styling
98+
vAPI.messaging.send('uDom', { what: 'uiStyles' }).then(response => {
99+
if ( typeof response !== 'object' || response === null ) { return; }
100+
if ( response.uiTheme !== 'unset' ) {
101+
if ( response.uiTheme === 'light' ) {
102+
root.classList.remove('dark');
103+
} else if ( response.uiTheme === 'dark' ) {
104+
root.classList.add('dark');
105+
}
106+
}
107+
if ( response.uiStyles !== 'unset' ) {
108+
document.body.style.cssText = response;
109+
}
110+
});
111+
96112
const root = DOMListFactory.root = document.querySelector(':root');
97113
if ( vAPI.webextFlavor.soup.has('mobile') ) {
98114
root.classList.add('mobile');
@@ -105,13 +121,6 @@ DOMListFactory.nodeFromSelector = function(selector) {
105121
if ( window.matchMedia('(prefers-color-scheme: dark)').matches ) {
106122
root.classList.add('dark');
107123
}
108-
109-
// https://github.com/uBlockOrigin/uBlock-issues/issues/1044
110-
// Offer the possibility to bypass uBO's default styling
111-
vAPI.messaging.send('uDom', { what: 'uiStyles' }).then(response => {
112-
if ( typeof response !== 'string' || response === 'unset' ) { return; }
113-
document.body.style.cssText = response;
114-
});
115124
}
116125

117126
/******************************************************************************/

0 commit comments

Comments
 (0)