forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfallback.ts
More file actions
66 lines (62 loc) · 2.25 KB
/
Copy pathfallback.ts
File metadata and controls
66 lines (62 loc) · 2.25 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
import {wasEnabledForHost} from './cache';
if (
document.documentElement instanceof HTMLHtmlElement &&
matchMedia('(prefers-color-scheme: dark)').matches &&
wasEnabledForHost() !== false &&
!document.querySelector('.darkreader--fallback') &&
!document.querySelector('.darkreader')
) {
const css = [
'html, body, body :not(iframe) {',
' background-color: #181a1b !important;',
' border-color: #776e62 !important;',
' color: #e8e6e3 !important;',
'}',
'html, body {',
' opacity: 1 !important;',
' transition: none !important;',
'}',
// MS Learn High Contrast issue
// https://github.com/darkreader/darkreader/issues/3618
'div[style*="background-color: rgb(135, 135, 135)"] {',
' background-color: #878787 !important;',
'}',
].join('\n');
const fallback = document.createElement('style');
fallback.classList.add('darkreader');
fallback.classList.add('darkreader--fallback');
fallback.media = 'screen';
fallback.textContent = css;
if (document.head) {
document.head.append(fallback);
} else {
const root = document.documentElement;
root.append(fallback);
const observer = new MutationObserver(() => {
if (document.head) {
observer.disconnect();
if (fallback.isConnected) {
document.head.append(fallback);
}
}
});
observer.observe(root, {childList: true});
}
}
declare const __FIREFOX_MV2__: boolean;
if (__FIREFOX_MV2__ && location.host === 'teams.live.com') {
// Microsoft Teams calls sheet.cssRules on extension styles and that
// causes "Not allowed to access cross-origin stylesheet" in Firefox
(() => {
const descriptor = Object.getOwnPropertyDescriptor(CSSStyleSheet.prototype, 'cssRules')!;
Object.defineProperty(CSSStyleSheet.prototype, 'cssRules', {
...descriptor,
get: function () {
if (this.ownerNode?.classList?.contains('darkreader')) {
return [];
}
return descriptor.get!.call(this) as CSSStyleSheet[];
},
});
})();
}