Night Mode - Darken Websites

Apply a dark theme to any webpage for better reading experience at night

// ==UserScript==
// @name         Night Mode - Darken Websites
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Apply a dark theme to any webpage for better reading experience at night
// @author       You
// @match        *://*/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // Adding CSS to change background and text colors for night mode
    GM_addStyle(`
        body {
            background-color: #121212 !important;
            color: #e0e0e0 !important;
        }
        a {
            color: #bb86fc !important;
        }
        header, footer, nav, .sidebar {
            background-color: #1f1f1f !important;
        }
        .button, .btn {
            background-color: #333 !important;
            color: #fff !important;
        }
        .highlight {
            background-color: #444 !important;
        }
    `);

    // Optionally, toggle mode with a key press (e.g., "N" key)
    document.addEventListener('keydown', function(e) {
        if (e.key === 'N' || e.key === 'n') {
            toggleNightMode();
        }
    });

    // Function to toggle night mode on/off
    function toggleNightMode() {
        const currentBgColor = document.body.style.backgroundColor;
        if (currentBgColor === 'rgb(18, 18, 18)') {
            document.body.style.backgroundColor = '#fff';
            document.body.style.color = '#000';
        } else {
            document.body.style.backgroundColor = '#121212';
            document.body.style.color = '#e0e0e0';
        }
    }
})();