// Function to change OpenWeb comment theme
function updateOpenWebTheme(isDarkMode) {
// Set the theme value
const themeValue = isDarkMode ? "dark" : "light";
// Select all OpenWeb modules
const modules = document.querySelectorAll('[data-spotim-module]');
// Update their theme attribute
modules.forEach(module => {
module.setAttribute('data-theme', themeValue);
});
// Try to reach into any iframes (may not work due to cross-origin restrictions)
document.querySelectorAll('iframe').forEach(iframe => {
try {
const iframeModules = iframe.contentDocument.querySelectorAll('[data-spotim-module]');
iframeModules.forEach(module => {
module.setAttribute('data-theme', themeValue);
});
} catch (e) {
// Cross-origin restriction likely prevented access
}
});
}
// Function to check if dark mode is active
function isDarkModeActive() {
return document.body.classList.contains('dark_mode');
}
// Initial run
updateOpenWebTheme(isDarkModeActive());
// Watch for changes to body class
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.attributeName === 'class') {
updateOpenWebTheme(isDarkModeActive());
}
});
});
observer.observe(document.body, { attributes: true });