Default YouTube to Dark Theme

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

目前為 2020-08-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Default YouTube to Dark Theme
// @version     0.1
// @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 last 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.