Skip to content

Commit 7ab91fa

Browse files
add option to force-apply dark/light theme (#3)
1 parent 528b8ec commit 7ab91fa

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
This is an extension for the browser extension [Tree Style Tabs](https://github.com/piroor/treestyletab#readme) (TST). It adds a search box at the bottom of TST's sidebar, allowing to search the titles and URLs (or whatever) of the tabs in the current window/sidebar, optionally case sensitive, as whole word, or by regular expression.
55
Matching tabs will be highlighted in the tree, and/or non-matches will be suppressed (see extension preferences).
6-
Should the search bar not show up after installing this extension, then have a look at `about:addons` > "Extensions" > "TST Tab Search".
6+
Should the search bar not show up after installing this extension, then have a look at `about:addons` > "Extensions" > "TST Tab Search" > "Preferences".
77

88
![Searching for Cats](./resources/screenshot.png)
99

src/common/options.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const model = {
1616
panel: {
1717
title: 'Search Box Options',
1818
expanded: true,
19-
description: `<small>These are only loaded when the TST sidebar (or a window) is first opened.</small>`,
19+
description: `<small>These are only applied when the search box is newly loaded in TST's sidebar. Click <code>(re-)register</code> above to force that.</small>`,
2020
default: true, children: {
2121
matchCase: {
2222
default: false,
@@ -30,9 +30,17 @@ const model = {
3030
default: false,
3131
input: { type: 'boolean', suffix: `<details><summary>Regular Expression:</summary>Search by (JavaScript) regular expression instead of plain string. If you don't know what this is, then you probably don't want it.</details>`, },
3232
},
33+
darkTheme: {
34+
default: null,
35+
input: { type: 'menulist', options: [
36+
{ value: null, label: `auto`, },
37+
{ value: false, label: `light`, },
38+
{ value: true, label: `dark`, },
39+
], prefix: `Color theme:`, },
40+
},
3341
placeholder: {
3442
default: 'Search ...',
35-
input: { type: 'string', prefix: 'Search box placeholder:', suffix: `<small>For those who want to customize/localize things.</small>`, },
43+
input: { type: 'string', prefix: 'Search box placeholder:', },
3644
},
3745
},
3846
},
@@ -128,11 +136,11 @@ const model = {
128136
advanced: {
129137
title: 'Experimental/Advanced Options',
130138
expanded: false,
131-
description: `Advanced and/or experimental options, that may break and/or disappear at any time. These may also require a reload of TST, this extension or the sidebars to apply.`,
139+
description: `Advanced and/or experimental options, that may break and/or disappear at any time.<br>These may also require a reload of TST, this extension or the sidebars to apply.`,
132140
default: true, children: {
133141
hideHeader: {
134142
title: 'Hide Header',
135-
description: `Hides the header above the search, that says something like "${manifest.name}".<br>NOTE: That header is not part of this extension, but of TST itself, and from a UX perspective, should absolutely be there (by default). It may (in the future?) also be used to switch sub panels or do any number of other things. Please DO NOT raise issues about anything loke that with TST while this option is active!`,
143+
description: `Hides the header above the search, that says something like "${manifest.name}". Requires re-registering above. On older versions of TST (before v3.7.5), also make sure to correctly size the panel before.<br>NOTE: That header is not part of this extension, but of TST itself, and from a UX perspective, should absolutely be there (by default). It may (in the future?) also be used to switch sub panels or do any number of other things. Please DO NOT raise issues about anything like that with TST while this option is active!`,
136144
default: '',
137145
input: { type: 'boolInt', suffix: `I vow to have read the above and not to annoy TST's authors about it.`, off: '', on: `
138146
#subpanel-container { height: 35px !important; }

src/content/embed.js

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
'fetch!./form.html': form_html,
44
}) => {
55

6+
document.documentElement.classList.toggle('dark-theme', global.matchMedia('(prefers-color-scheme: dark)').matches);
7+
68
document.body.insertAdjacentHTML('beforeend', form_html);
79

810
const names = [ 'term', 'matchCase', 'wholeWord', 'regExp', ];
@@ -30,5 +32,11 @@ document.addEventListener('keydown', event => {
3032
const options = (await messages.request('getOptions'));
3133
names.slice(1).forEach(name => { inputs[name].checked = options[name]; });
3234
inputs.term.placeholder = options.placeholder;
35+
if (options.darkTheme != null) {
36+
document.documentElement.classList.toggle('dark-theme', options.darkTheme);
37+
} else {
38+
global.matchMedia('(prefers-color-scheme: dark)').onchange = ({ matches, }) =>
39+
document.documentElement.classList.toggle('dark-theme', matches);
40+
}
3341

3442
}); })(this);

src/content/form.html

+8-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
margin: 2px; height: 19px; width: 19px;
2525
border: 1px solid;
2626
}
27+
#options label:not(:hover) div {
28+
opacity: .75;
29+
}
2730
#options input:not(:checked) + label {
2831
background-color: transparent;
2932
border-color: transparent;
@@ -55,17 +58,17 @@
5558
}
5659
#options label div { border-color: var(--button-fgc); }
5760
/* light */ :root {
58-
--input-bgc: #e2e1d5;
61+
--input-bgc: #f9f9fa;
5962
--input-fgc: #222;
6063
--button-bgc: #0002;
6164
--button-bdc: #0005;
62-
--button-fgc: #444;
65+
--button-fgc: #000;
6366
}
64-
@media (prefers-color-scheme: dark) { :root {
67+
:root.dark-theme {
6568
--input-bgc: #1D2328;
6669
--input-fgc: #ddd;
6770
--button-bgc: #fff3;
6871
--button-bdc: #fff5;
69-
--button-fgc: #aaa;
70-
} }
72+
--button-fgc: #fff;
73+
}
7174
</style>

src/views/options.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
'background/': { register, },
66
}) => async (window, location) => { const { document, } = window;
77

8-
document.head.insertAdjacentHTML('beforeend', `<style>
8+
document.head.insertAdjacentHTML('beforeend', String.raw`<style>
99
/* details in checkbox descriptions */
1010
.checkbox-wrapper { vertical-align: top !important; }
1111
.value-suffix details[open] { max-width: calc(100% - 40px); }
1212
1313
/* fix lists in descriptions */
1414
.pref-description li:not(#not) { list-style: unset; margin-left: 6px; }
15+
16+
#\.panel\.placeholder input { max-width: 150px; }
1517
</style>`);
1618

1719
async function onCommand({ name, }, _buttonId) { try { switch (name) {

0 commit comments

Comments
 (0)