Dark/Light Mode Toggle

Toggle between dark and light mode on any website

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Dark/Light Mode Toggle
// @namespace    http://your.namespace.com
// @version      1.2
// @description  Toggle between dark and light mode on any website
// @author       Your Name
// @license      MIT
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const toggleButton = document.createElement('button');
    toggleButton.textContent = 'Toggle Dark/Light Mode';
    toggleButton.style.position = 'fixed';
    toggleButton.style.top = '20px';
    toggleButton.style.right = '20px';
    document.body.appendChild(toggleButton);

    let darkModeEnabled = localStorage.getItem('darkModeEnabled') === 'true';
    setMode(darkModeEnabled);

    toggleButton.addEventListener('click', () => {
        darkModeEnabled = !darkModeEnabled;
        setMode(darkModeEnabled);
        localStorage.setItem('darkModeEnabled', darkModeEnabled);
    });

    function setMode(isDarkMode) {
        if (isDarkMode) {
            document.documentElement.style.backgroundColor = '#1a1a1a';
            document.documentElement.style.color = '#ffffff';
        } else {
            document.documentElement.style.backgroundColor = '#ffffff';
            document.documentElement.style.color = '#000000';
        }
    }
})();