X.com Night Mode Cookie Setter

Detect system color scheme and set night_mode cookie on X.com

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!)

Autore
adlkt
Installazioni giornaliere
0
Installazioni totali
19
Valutazione
0 0 0
Versione
0.1
Creato il
01/03/2025
Aggiornato il
01/03/2025
Dimensione
1,31 KB
Licenza
MIT
Applica a

X.com Night Mode Cookie Setter

A simple Tampermonkey userscript that automatically detects your system's color scheme (light or dark mode) and sets the night_mode cookie on X.com accordingly. This ensures that X.com's theme aligns with your system preferences without manual intervention.

Features

  • Automatic Detection: Uses matchMedia to detect whether your system is in light or dark mode.
  • Cookie Setting: Sets the night_mode cookie to 0 for light mode or 2 for dark mode.
  • Dynamic Updates: Listens for system theme changes and updates the cookie in real-time.
  • Long-lasting Cookie: Cookie persists for 1 year (max-age=31536000).

Installation

  1. Install Tampermonkey in your browser.
  2. Create a new script in Tampermonkey.
  3. Copy and paste the script code into the editor.
  4. Save the script and visit x.com to see it in action.

Script Details

How It Works

  • On page load, the script checks your system's color scheme using window.matchMedia('(prefers-color-scheme: dark)').
  • It sets the night_mode cookie to:
    • 0 if the system is in light mode.
    • 2 if the system is in dark mode.
  • The cookie is applied to the x.com domain with a 1-year expiration.
  • If your system theme changes (e.g., switching from light to dark mode), the script detects this and updates the cookie automatically.

Debugging

  • Open your browser's developer console (F12) to see log messages confirming the detected mode and cookie value:
    • Example: System is in dark mode. Set night_mode cookie to 2