X.com Night Mode Cookie Setter

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

作者
adlkt
今日安裝
0
安裝總數
14
評價
0 0 0
版本
0.1
建立日期
2025-03-01
更新日期
2025-03-01
尺寸
1.3 KB
授權條款
MIT
腳本執行於

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