X.com Night Mode Cookie Setter

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

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

Autor
adlkt
Instalaciones diarias
0
Instalaciones totales
15
Calificaciones
0 0 0
Versión
0.1
Creado
1/3/2025
Actualizado
1/3/2025
Tamaño
1,31 KB
Licencia
MIT
Funciona en

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