forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwindow-theme.ts
More file actions
96 lines (91 loc) · 3.15 KB
/
Copy pathwindow-theme.ts
File metadata and controls
96 lines (91 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import type {RGBA} from '../utils/color';
import {parseColorWithCache} from '../utils/color';
import {modifyBackgroundColor, modifyForegroundColor, modifyBorderColor} from '../generators/modify-colors';
import type {Theme} from '../definitions';
// TODO: remove type after dependency update
declare const browser: {
theme: {
update: ((theme: any) => Promise<void>);
reset: (() => Promise<void>);
};
};
const themeColorTypes: { [key: string]: 'bg' | 'text' | 'border' } = {
accentcolor: 'bg',
button_background_active: 'text',
button_background_hover: 'text',
frame: 'bg',
icons: 'text',
icons_attention: 'text',
ntp_background: 'bg',
ntp_text: 'text',
popup: 'bg',
popup_border: 'bg',
popup_highlight: 'bg',
popup_highlight_text: 'text',
popup_text: 'text',
sidebar: 'bg',
sidebar_border: 'border',
sidebar_text: 'text',
tab_background_text: 'text',
tab_line: 'bg',
tab_loading: 'bg',
tab_selected: 'bg',
textcolor: 'text',
toolbar: 'bg',
toolbar_bottom_separator: 'border',
toolbar_field: 'bg',
toolbar_field_border: 'border',
toolbar_field_border_focus: 'border',
toolbar_field_focus: 'bg',
toolbar_field_separator: 'border',
toolbar_field_text: 'text',
toolbar_field_text_focus: 'text',
toolbar_text: 'text',
toolbar_top_separator: 'border',
toolbar_vertical_separator: 'border',
};
const $colors: { [key: string]: string } = {
// 'accentcolor' is the deprecated predecessor of 'frame'.
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/theme#colors
accentcolor: '#111111',
frame: '#111111',
ntp_background: 'white',
ntp_text: 'black',
popup: '#cccccc',
popup_text: 'black',
sidebar: '#cccccc',
sidebar_border: '#333',
sidebar_text: 'black',
tab_background_text: 'white',
tab_loading: '#23aeff',
// 'textcolor' is the predecessor of 'tab_background_text'.
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/theme#colors
textcolor: 'white',
toolbar: '#707070',
toolbar_field: 'lightgray',
toolbar_field_text: 'black',
};
export function setWindowTheme(theme: Theme): void {
const colors = Object.entries($colors).reduce((obj: { [key: string]: string }, [key, value]) => {
const type: 'bg' | 'text' | 'border' = themeColorTypes[key];
const modify: ((rgb: RGBA, theme: Theme) => string) = {
'bg': modifyBackgroundColor,
'text': modifyForegroundColor,
'border': modifyBorderColor,
}[type];
const rgb = parseColorWithCache(value)!;
const modified = modify(rgb, theme);
obj[key] = modified;
return obj;
}, {});
if (typeof browser !== 'undefined' && browser.theme && browser.theme.update) {
browser.theme.update({colors});
}
}
export function resetWindowTheme(): void {
if (typeof browser !== 'undefined' && browser.theme && browser.theme.reset) {
// BUG: resets browser theme to entire
// https://bugzilla.mozilla.org/show_bug.cgi?id=1415267
browser.theme.reset();
}
}