forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow-theme.ts
More file actions
85 lines (80 loc) · 2.7 KB
/
Copy pathwindow-theme.ts
File metadata and controls
85 lines (80 loc) · 2.7 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
import {parse, RGBA} from '../utils/color';
import {modifyBackgroundColor, modifyForegroundColor, modifyBorderColor} from '../generators/modify-colors';
import {FilterConfig} from '../definitions';
declare const browser: {
theme: {
update: ((theme: any) => Promise<void>);
reset: (() => Promise<void>);
};
};
const themeColorTypes = {
accentcolor: 'bg',
button_background_active: 'text',
button_background_hover: 'text',
frame: 'bg',
icons: 'text',
icons_attention: 'text',
popup: 'bg',
popup_border: 'bg',
popup_highlight: 'bg',
popup_highlight_text: 'text',
popup_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 = {
// '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',
popup: '#cccccc',
popup_text: 'black',
tab_background_text: 'white',
tab_line: '#23aeff',
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(filter: FilterConfig) {
const colors = Object.entries($colors).reduce((obj, [key, value]) => {
const type = themeColorTypes[key];
const modify: ((rgb: RGBA, filter: FilterConfig) => string) = {
'bg': modifyBackgroundColor,
'text': modifyForegroundColor,
'border': modifyBorderColor,
}[type];
const rgb = parse(value);
const modified = modify(rgb, filter);
obj[key] = modified;
return obj;
}, {});
if (typeof browser !== 'undefined' && browser.theme && browser.theme.update) {
browser.theme.update({colors});
}
}
export function resetWindowTheme() {
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();
}
}