Skip to content

Instantly share code, notes, and snippets.

@fanzeyi
Last active December 17, 2024 00:08
Show Gist options
  • Save fanzeyi/6bc0c8e9fa560f6bd38eb36f7f749468 to your computer and use it in GitHub Desktop.
Save fanzeyi/6bc0c8e9fa560f6bd38eb36f7f749468 to your computer and use it in GitHub Desktop.
Twitter Auto Dark Mode
// ==UserScript==
// @name Twitter auto darkmode
// @version 1
// @grant none
// @match *://twitter.com/*
// ==/UserScript==
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
const isDarkMode = e.matches ? 1 : 0;
document.cookie = `night_mode=${isDarkMode};path=/;domain=.twitter.com;secure`;
});
@surfaceflinger
Copy link

after rebrand

// ==UserScript==
// @name     Twitter auto darkmode
// @version  1
// @grant    none
// @match    *://twitter.com/*
// @match    *://x.com/*
// ==/UserScript==

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
  const isDarkMode = e.matches ? 1 : 0;
  document.cookie = `night_mode=${isDarkMode};path=/;domain=.twitter.com;secure`;
  document.cookie = `night_mode=${isDarkMode};path=/;domain=.x.com;secure`;
});

@J-McFc
Copy link

J-McFc commented Dec 16, 2024

If you prefer the dark mode to be lights out instead of dim, change this line:

const isDarkMode = e.matches ? 1 : 0;

to this:

const isDarkMode = e.matches ? 2 : 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment