GitLab Dark Theme

Forces GitLab to use it's dark mode when not logged in.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        GitLab Dark Theme
// @namespace   https://greatest.deepsurf.us/users/581142
// @include     /^https?:\/{2}(?:git(?:\.(?:linux-kernel\.at|coop|fosscommunity\.in|jami\.net|oeru\.org|pleroma\.social)|lab\.(?:com|(?:gnome|haskell|trisquel|torproject|isc)\.org|e\.foundation|freedesktop\.org)|gud\.io)|(?:code\.(?:briarproject|videolan)|0xacab|salsa\.debian|framagit|dev\.gajim)\.org||lab\.libreho\.st)\//
// @grant       none
// @version     1.0.6
// @author      brian6932
// @run-at      document-start
// @license		MPL-2.0
// @description Forces GitLab to use it's dark mode when not logged in.
// ==/UserScript==
// jshint esversion: 11

// I can't do anything about the initial screen flash.
const
	dark = () => {
		if (!globalThis.document.cookie.includes('gitlab_user=true')) {
			const oldGon = globalThis.gon
			globalThis.Object.defineProperties(
				globalThis.Object.defineProperty(globalThis, 'gon', {
					__proto__: null,
					value: { __proto__: null },
					enumerable: true,
					configurable: true
				}).gon,
				{
					__proto__: null,
					user_color_scheme: {
						__proto__: null,
						value: 'dark',
						enumerable: true
					},
					user_color_mode: {
						__proto__: null,
						value: 'gl-system',
						enumerable: true
					}
				}
			)

			if (oldGon)
				for (const prop in oldGon)
					if (!(prop in globalThis.gon))
						globalThis.gon[prop] = oldGon[prop]

			globalThis.document.documentElement.classList.add('gl-dark')
		}
	},
	eventType = 'beforescriptexecute'

// Chromium and WebKit don't support this for some reason, and I cba to use a polyfill here.
if (GM_info.platform.browserName === 'Firefox' || globalThis.geteventTypeListeners?.(globalThis).hasOwnProperty(eventType))
	globalThis.addEventListener(eventType, dark)
else
	dark()