-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdark-detection.js
32 lines (29 loc) · 1.16 KB
/
dark-detection.js
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
function waitFor(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
waitFor("a[data-original-title='风格选择']").then(() => {
console.log('Detecting dark mode...')
const __darkIndicator = document.querySelector("a[data-original-title='风格选择']");
if (__darkIndicator !== null) {
if (__darkIndicator.innerHTML === '暗夜黑') {
console.log('[XFMD] Detected dark mode.');
document.querySelector('.xfPreview')?.classList.add('dark');
document.querySelectorAll('article.message-body').forEach(e => e.classList.add('dark'));
document.querySelectorAll('article.resourceBody-main').forEach(e => e.classList.add('dark'));
}
}
})