Greasy Fork is available in English.

GitLab Dark Mode When Not Logged In

For some reason you can't enable dark theme if you are not logged in, but with this script you can!

  1. // ==UserScript==
  2. // @name GitLab Dark Mode When Not Logged In
  3. // @description For some reason you can't enable dark theme if you are not logged in, but with this script you can!
  4. // @version 1.0.0
  5. // @author Pabli
  6. // @namespace https://github.com/pabli24
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=gitlab.com
  8. // @license MIT
  9. // @match https://gitlab.com/*
  10. // @run-at document-body
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. const isLight = document.documentElement.classList.contains('gl-light');
  15. const isDark = document.documentElement.classList.contains('gl-dark');
  16. const isNotLoggedIn = document.querySelector('header').classList.contains('header-logged-out');
  17.  
  18. if (isLight && !isDark && isNotLoggedIn) {
  19. document.documentElement.classList.replace('gl-light', 'gl-dark');
  20. document.head.innerHTML += '<meta name="color-scheme" content="dark light" />';
  21. document.head.innerHTML += '<link rel="stylesheet" href="/assets/application_dark-449c0613e86649a202dfb0d731bf88a31c63817b6e76fa7cc0ff22bb00af6106.css" />';
  22. document.head.innerHTML += '<link rel="stylesheet" href="/assets/highlight/themes/dark-d3b12a96d7c0b736869f2869cd6bf53fc38874df1fd29dfc0018b772e7d95eb6.css" />';
  23. const observer = new MutationObserver(mutations => {
  24. document.querySelectorAll('.white').forEach(element => {
  25. element.classList.replace('white', 'dark');
  26. });
  27. });
  28. observer.observe(document.body, { childList: true, subtree: true });
  29. }