Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A simple Chrome extension for toggling dark mode on any webpage with smart CSS adaptation and domain-level control

License

Notifications You must be signed in to change notification settings

KingMario/dark-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dark Mode Toggle Chrome Extension

A simple and easy-to-use Chrome browser extension that can quickly toggle dark mode for any webpage.

Features

  • πŸŒ™ One-click toggle - Click the extension icon to toggle dark mode for the current webpage
  • πŸ’Ύ State persistence - Dark mode settings for each website are saved
  • 🌐 Domain-level control - Option to apply settings to all pages under the entire domain
  • 🎨 Smart adaptation - Automatically handles images, videos, and existing dark themes
  • ⚑ Performance optimized - Uses CSS filter technology for rapid response
  • πŸ”„ Real-time sync - Multiple tab states sync in real-time
  • 🎯 Precise control - Supports reset functionality and keyboard shortcuts

Installation

Install from source code (Developer mode)

  1. Download or clone this project to your local machine
  2. Open Chrome browser and go to chrome://extensions/
  3. Enable "Developer mode" in the top right corner
  4. Click "Load unpacked extension"
  5. Select the project folder (directory containing manifest.json)
  6. Extension installation complete!

Usage

Basic operations

  1. Toggle dark mode: Click the extension icon in the browser toolbar
  2. Check status: The extension popup shows the current website's dark mode status
  3. Apply to entire domain: Check "Apply to entire domain" option to apply settings to all pages under the same domain
  4. Reset settings: Click "Reset Settings" button in the popup to clear current website or domain settings

Keyboard shortcuts

  • Space key: Press space in the extension popup to toggle dark mode
  • Cmd/Ctrl + R: Press in the extension popup to reset settings

Technical Implementation

Core technology

  • Uses intelligent CSS style replacement instead of simple filter inversion
  • Directly sets background color to dark (#121212, #1e1e1e) and text color to light (#e8e6e3)
  • Maintains original display effects for images, videos, and other media elements
  • Uses Chrome Extension Manifest V3
  • Intelligently handles inline styles and dynamic content

Dark mode implementation approach

  1. Color mapping: Maps white backgrounds to dark colors, black text to light colors
  2. Media protection: Images and videos maintain original colors, only adjusting opacity
  3. Smart detection: Automatically identifies and handles inline styles
  4. Dynamic adaptation: Monitors DOM changes and applies dark mode to new elements in real-time
  5. Performance optimization: Uses CSS variables and efficient selectors

File structure

dark-mode/
β”œβ”€β”€ manifest.json          # Extension configuration file
β”œβ”€β”€ popup/                 # Extension popup interface
β”‚   β”œβ”€β”€ popup.html
β”‚   β”œβ”€β”€ popup.css
β”‚   └── popup.js
β”œβ”€β”€ content/               # Content scripts
β”‚   β”œβ”€β”€ content.js         # Main dark mode logic
β”‚   └── dark-mode.css      # Dark mode styles
β”œβ”€β”€ background/            # Background script
β”‚   └── background.js
β”œβ”€β”€ icons/                 # Extension icons
β”‚   β”œβ”€β”€ icon.svg
β”‚   β”œβ”€β”€ icon16.png
β”‚   β”œβ”€β”€ icon32.png
β”‚   β”œβ”€β”€ icon48.png
β”‚   └── icon128.png
└── README.md             # Documentation

Compatibility

  • βœ… Chrome 88+
  • βœ… Edge 88+
  • βœ… Other Chromium-based browsers

Website adaptation

The extension has special optimizations for the following websites:

  • GitHub
  • GitLab
  • Zhihu
  • Twitter/X
  • YouTube
  • Reddit
  • Stack Overflow
  • Wikipedia

FAQ

Q: What if dark mode doesn't look good on some websites?

A: You can click the "Reset Settings" button, or use the native dark mode on that website.

Q: Will dark mode affect image display?

A: No, the extension automatically maintains original colors for images and videos.

Q: What if the page turns black but text is invisible?

A: This issue has been fixed in the new version. If you still encounter it, please:

  1. Refresh the page to reload the extension
  2. Click the reset button to clear settings
  3. Reinstall the extension

Q: Will settings sync to other devices?

A: Currently settings are only saved locally and do not support cross-device sync.

Q: How to uninstall the extension?

A: Go to chrome://extensions/ page, find the extension, and click "Remove".

Q: Why don't some elements turn dark?

A: The extension automatically skips websites and elements that already have dark themes to avoid double inversion.

Testing

After installing the extension, you can test dark mode effects on any webpage:

  1. Visit any webpage (like Baidu, GitHub, Weibo, etc.)
  2. Click the extension icon to enable dark mode
  3. Check if various elements display correctly

Development

Development environment

  • Node.js 16+
  • Chrome 88+

Debugging methods

  1. Click "Reload" in the extension management page to update the extension
  2. Right-click extension icon β†’ "Inspect popup" to debug popup
  3. Press F12 on the webpage β†’ Console to view content script logs
  4. In chrome://extensions/ click "Background page" to debug background script

Custom modifications

  • Modify content/content.js to adjust dark mode algorithm
  • Modify popup/popup.css to customize popup styles
  • Modify content/dark-mode.css to add specific website adaptations

License

MIT License

Copyright (c) 2025-2026 Mario Studio

See LICENSE file for details

Contributing

Issues and Pull Requests are welcome!

Changelog

v1.0.0

  • Initial version
  • Basic dark mode toggle functionality
  • State persistence storage
  • Smart media element handling

About

A simple Chrome extension for toggling dark mode on any webpage with smart CSS adaptation and domain-level control

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published