Default YouTube to Dark Theme

Makes YouTube default to its Dark Theme by initialising the relevant cookie

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        Default YouTube to Dark Theme
// @version     0.2
// @description Makes YouTube default to its Dark Theme by initialising the relevant cookie
// @author      uxamend
// @namespace   https://greasyfork.org/en/users/231373-uxamend
// @match       *://*.youtube.com/*
// @grant       none
// @run-at      document-start
// @license     CC0-1.0
// ==/UserScript==

"use strict";

var c = document.cookie

// If there's no PREF cookie, then create one with a value that enables the Dark Theme
if(!c || !c.match("^PREF=|; ?PREF=")) {
  document.cookie = "PREF=f6=400;domain=youtube.com";
}

// We are only interested in setting the cookie if this is the first visit to YouTube since
// cookies were cleared/deleted.
// 
// If the cookie already exists, then we don't need or want to do anything.
//
// Overwriting an existing PREF cookie could risk data loss of other preferences, since we
// don't know how exactly preferences are expressed. All we know is that PREF=f6=400
// gives us YouTube's defaults except with Dark Theme enabled.