Darkmode User

Darkmode for the websites.

06.02.2021 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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