Skip to content

Commit

Permalink
Add advanced setting to force a light/dark theme
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Oct 3, 2020
1 parent b179dc0 commit e3a6d84
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/css/logger-ui-inspector.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
padding-left: 0.5em;
}
#domInspector ul {
background-color: #fff;
background-color: var(--default-surface);
margin: 0;
padding-left: 1em;
}
Expand All @@ -37,7 +37,7 @@
color: #aaa;
}
#domInspector li > span:first-child {
color: #000;
color: var(--default-ink);
cursor: default;
font-size: 1rem;
margin-right: 0;
Expand Down
16 changes: 8 additions & 8 deletions src/css/logger-ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ textarea {
width: 100%;
}
.permatoolbar {
background-color: white;
background-color: var(--default-surface);
border: 0;
box-sizing: border-box;
display: flex;
Expand All @@ -34,7 +34,7 @@ textarea {
fill: #5F9EA0;
}
.permatoolbar .button:hover {
background-color: #eee;
background-color: var(--default-surface-hover);
}
#pageSelector {
min-width: 10em;
Expand Down Expand Up @@ -135,7 +135,7 @@ body[dir="rtl"] #pageSelector {
transform: scaleY(1);
}
#netInspector #filterExprPicker {
background-color: white;
background-color: var(--default-surface);
border: 1px solid gray;
display: none;
position: absolute;
Expand Down Expand Up @@ -445,7 +445,7 @@ body.colorBlind #netFilteringDialog > .panes > .details > div[data-status="2"] b
}

#popupContainer {
background: white;
background-color: var(--default-surface);
border: 1px solid gray;
bottom: 0;
display: none;
Expand Down Expand Up @@ -481,7 +481,7 @@ body.colorBlind #netFilteringDialog > .panes > .details > div[data-status="2"] b
position: relative;
}
#modalOverlay > div > div:nth-of-type(1) {
background-color: white;
background-color: var(--default-surface);
border: 0;
box-sizing: border-box;
padding: 1em;
Expand All @@ -490,13 +490,13 @@ body.colorBlind #netFilteringDialog > .panes > .details > div[data-status="2"] b
width: 90vw;
}
#modalOverlay > div > div:nth-of-type(2) {
stroke: #000;
stroke: var(--default-ink);
stroke-width: 3px;
position: absolute;
width: 1.6em;
height: 1.6em;
bottom: calc(100% + 2px);
background-color: white;
background-color: var(--default-surface);
}
body[dir="ltr"] #modalOverlay > div > div:nth-of-type(2) {
right: 0;
Expand All @@ -505,7 +505,7 @@ body[dir="rtl"] #modalOverlay > div > div:nth-of-type(2) {
left: 0;
}
#modalOverlay > div > div:nth-of-type(2):hover {
background-color: #eee;
background-color: var(--default-surface-hover);
}
#modalOverlay > div > div:nth-of-type(2) > * {
pointer-events: none;
Expand Down
1 change: 1 addition & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const µBlock = (( ) => { // jshint ignore:line
uiPopupConfig: 'undocumented',
uiFlavor: 'unset',
uiStyles: 'unset',
uiTheme: 'unset',
updateAssetBypassBrowserCache: false,
userResourcesLocation: 'unset',
};
Expand Down
5 changes: 4 additions & 1 deletion src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ const onMessage = function(request, sender, callback) {
break;

case 'uiStyles':
response = µb.hiddenSettings.uiStyles;
response = {
uiStyles: µb.hiddenSettings.uiStyles,
uiTheme: µb.hiddenSettings.uiTheme,
};
break;

case 'userSettings':
Expand Down
23 changes: 16 additions & 7 deletions src/js/udom.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ DOMListFactory.nodeFromSelector = function(selector) {
/******************************************************************************/

{
// https://github.com/uBlockOrigin/uBlock-issues/issues/1044
// Offer the possibility to bypass uBO's default styling
vAPI.messaging.send('uDom', { what: 'uiStyles' }).then(response => {
if ( typeof response !== 'object' || response === null ) { return; }
if ( response.uiTheme !== 'unset' ) {
if ( response.uiTheme === 'light' ) {
root.classList.remove('dark');
} else if ( response.uiTheme === 'dark' ) {
root.classList.add('dark');
}
}
if ( response.uiStyles !== 'unset' ) {
document.body.style.cssText = response;
}
});

const root = DOMListFactory.root = document.querySelector(':root');
if ( vAPI.webextFlavor.soup.has('mobile') ) {
root.classList.add('mobile');
Expand All @@ -105,13 +121,6 @@ DOMListFactory.nodeFromSelector = function(selector) {
if ( window.matchMedia('(prefers-color-scheme: dark)').matches ) {
root.classList.add('dark');
}

// https://github.com/uBlockOrigin/uBlock-issues/issues/1044
// Offer the possibility to bypass uBO's default styling
vAPI.messaging.send('uDom', { what: 'uiStyles' }).then(response => {
if ( typeof response !== 'string' || response === 'unset' ) { return; }
document.body.style.cssText = response;
});
}

/******************************************************************************/
Expand Down

0 comments on commit e3a6d84

Please sign in to comment.