Darkmode User

Darkmode for the websites.

Від 06.02.2021. Дивіться остання версія.

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 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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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         Darkmode User
// @version      1.0
// @namespace    https://github.com/Purfview/Darkmode-User
// @description  Darkmode for the websites.
// @icon         https://i.imgur.com/ZftAaI6.png
// @license      MIT
//
//
// @require      https://cdn.jsdelivr.net/npm/[email protected]/lib/darkmode-js.min.js
//
// @include      https://karagarga.in/*
//
// ==/UserScript==
//
/*=========================  Version History  ==================================

1.0   -   First public release, only one site added.

==============================================================================*/

function addGlobalStyles(css) {
  var head, style;
  head = document.getElementsByTagName('head')[0];
  if (!head) { return; }
  style = document.createElement('style');
  style.className = 'DarkmodeUser';
  style.innerHTML = css;
  head.appendChild(style);
}

function removeGlobalStyles() {  
  var removeEl = [].slice.apply(document.getElementsByClassName("DarkmodeUser"));
  for (var i = 0; i < removeEl.length; i++) {
    removeEl[i].className = removeEl[i].remove();
  }
}

function toggleGlobalStyles() {
  var modestate = window.localStorage['darkmode'];
  if (modestate == "true") {
    const urlHost = window.location.hostname;
    const urlPath = window.location.pathname;
    if (urlHost == 'karagarga.in') {
      if (urlPath == '/browse.php'     ||
          urlPath == '/current.php'    ||
          urlPath == '/history.php'    ||
          urlPath == '/friends.php'    ||
          urlPath == '/bookmarks.php'  ||
          urlPath == '/mytorrents.php' ||
          urlPath == '/userdetails.php' ) {
          addGlobalStyles('img {mix-blend-mode: screen}');
          addGlobalStyles('a div img {mix-blend-mode: normal}');
          addGlobalStyles('table .clear {isolation: isolate}');     
      } else {
          addGlobalStyles('img {mix-blend-mode: screen}');
          addGlobalStyles('table .main {isolation: isolate}');
          addGlobalStyles('table .main img {mix-blend-mode: difference}');
          addGlobalStyles('.spoiler {isolation: isolate}');
          addGlobalStyles('.spoiler img {mix-blend-mode: difference}');
          addGlobalStyles('table .clear {isolation: isolate}');     
      }
    }
  } else {
      removeGlobalStyles();
  } 
}

function addDarkmodeWidget() {
  const options = {
    bottom: '32px',
    right: '32px',
    left: 'unset',
    time: '0.0s',
    mixColor: '#fff',
    backgroundColor: '#fff',
    buttonColorDark: '#100f2c',
    buttonColorLight: '#fff',
    saveInCookies: true,
    label: '',
    autoMatchOsTheme: false
  };
  new Darkmode(options).showWidget();
  document.getElementsByClassName('darkmode-toggle')[0].onclick = function () {toggleGlobalStyles()};
  
  const darkmode = window.localStorage['darkmode'];
  if (darkmode == "true") {
    toggleGlobalStyles();
  }
}

window.addEventListener('load', addDarkmodeWidget);