-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzatrolene-hry.cz-dark-theme-background-remover.user.js
57 lines (49 loc) · 2.07 KB
/
zatrolene-hry.cz-dark-theme-background-remover.user.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
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
// ==UserScript==
// @name Remove Background Image in Dark Mode @zatrolene-hry.cz
// @namespace https://github.com/kofaysi/general-userscripts/blob/main/zatrolene-hry.cz-dark-theme-background-remover.user.js
// @version 1.9
// @description Remove the background image from body and footer elements on Zatrolene Hry, but only when dark mode is enabled in the browser
// @author https://github.com/kofaysi/
// @match *://www.zatrolene-hry.cz/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// Function to remove background images from the body and footer elements
function removeBackgroundImages() {
// Remove the background image from the body
const bodyElement = document.body;
bodyElement.style.backgroundImage = 'none';
// Remove the background image from the footer
const footerElement = document.querySelector('.footer');
if (footerElement) {
footerElement.style.backgroundImage = 'none';
}
}
// Check if dark mode is enabled in the user's browser
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
// Apply background removal if dark mode is enabled
function checkDarkModeAndApply() {
if (darkModeMediaQuery.matches) {
removeBackgroundImages();
}
}
// Run the check once the page is loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', checkDarkModeAndApply);
} else {
checkDarkModeAndApply();
}
// Listen for changes in the user's dark mode preference
darkModeMediaQuery.addListener(checkDarkModeAndApply);
// Additional fallback for when background changes dynamically after load
new MutationObserver(() => {
if (darkModeMediaQuery.matches) {
removeBackgroundImages();
}
}).observe(document.body, {
attributes: true, // Listen for attribute changes
attributeFilter: ['style'] // Specifically monitor style changes
});
})();