Darkmode User

Darkmode for the websites.

Stan na 06-02-2021. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);