DarkTube

Set dark mode on youtube and turn off autoplay next video

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name            DarkTube
// @name:ru         DarkTube
// @namespace       darktube
// @version         0.2
// @description     Set dark mode on youtube and turn off autoplay next video
// @description:ru  Устанавливает темный режим на ютюбе и выключает автозапуск следующего видео
// @author          Blank
// @match           https://www.youtube.com/*
// @run-at          document-start
// @grant           none
// @noframes
// ==/UserScript==

(function main() {
  'use strict';

  const log = (...args) => console.log(`${GM.info.script.name}:`, ...args);
  log('start');

  // set darkmode and autopay off cookie before page loaded

  const cookiePref = document.cookie.replace(/(?:(?:^|.*;\s*)PREF\s*=\s*([^;]*).*$)|^.*$/, '$1');
  const prefDarkAndAutopay = 'f6=400&f5=30000';
  if (!cookiePref.includes(prefDarkAndAutopay)) {
    document.cookie = `PREF=${cookiePref ? `&${cookiePref}` : ''}${prefDarkAndAutopay};path=/;domain=.youtube.com;max-age=315360000`;
    log('cookie injected');
  }

}());