Simple Dark Mode

Simple Dark Mode for any site

You will need to install an extension such as Tampermonkey, Greasemonkey 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 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.

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

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

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         		Simple Dark Mode
// @description                 Simple Dark Mode for any site
// @namespace    		http://your.namespace.com
// @version      		0.01
// @author       		bunny777
// @grant        		none
// @match        		*://*/*
// @license MIT
// ==/UserScript==

(() => {
  'use strict';

  const toggleButton = document.createElement('button'),
    style = document.createElement('style');

  toggleButton.innerText = 'ON';
  toggleButton.style.position = 'fixed';
  toggleButton.style.width = '30px';
  toggleButton.style.top = '5px';
  toggleButton.style.right = '5px';
  toggleButton.style.padding = '5px';
  toggleButton.style.border = 'none';
  toggleButton.style.borderRadius = '20px';
  toggleButton.style.backgroundColor = '#000000';
  toggleButton.style.color = '#ffffff';
  toggleButton.style.fontSize = '10px';
  toggleButton.style.cursor = 'pointer';
  toggleButton.style.boxShadow = '2px';
  toggleButton.style.zIndex = 9999;
  document.body.appendChild(toggleButton);

  function darkMode() {
    style.innerText = 'html,img,video,button,svg:not(button svg),canvas {filter: invert(.9);}';
    document.head.appendChild(style);
  }
  darkMode();

  document.addEventListener('DOMContentLoaded', darkMode);
  toggleButton.addEventListener('click', () => {

    if (style.innerText === 'html,img,video,button,svg:not(button svg),canvas {filter: invert(0);}') {
      style.innerText = 'html,img,video,button,svg:not(button svg),canvas {filter: invert(.9);}';
      toggleButton.innerText = 'ON';
    } else {
      style.innerText = 'html,img,video,button,svg:not(button svg),canvas {filter: invert(0);}';
      toggleButton.innerText = 'OFF';
    }
    document.head.appendChild(style);
  });
})();