-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlight-dark-modes.js
30 lines (27 loc) · 919 Bytes
/
light-dark-modes.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
// Function to update the classes of all <table> elements
function updateTableClasses(isDarkMode) {
const tables = document.getElementsByTagName('table');
for (const table of tables) {
if (isDarkMode) {
table.classList.add('table-dark');
} else {
table.classList.remove('table-dark');
}
}
}
// Updation on initial page load
document.addEventListener('DOMContentLoaded', () => {
const body = document.body;
const isDarkMode = body.classList.contains('quarto-dark');
updateTableClasses(isDarkMode);
});
// Watch for changes in the class of <body>
const bodyObserver = new MutationObserver((mutationsList) => {
const isDarkMode = mutationsList[0].target.classList.contains('quarto-dark');
updateTableClasses(isDarkMode);
});
const body = document.body;
bodyObserver.observe(body, {
attributes: true,
attributeFilter: ['class']
});