All Projects → sandoche → Darkmode.js

sandoche / Darkmode.js

Licence: mit
🌓 Add a dark-mode / night-mode to your website in a few seconds

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to Darkmode.js

DiscordNight
An actual Dark/Nightmode Theme for Discord/BetterDiscord
Stars: ✭ 86 (-96.32%)
Mutual labels:  dark-theme, dark, darkmode, nightmode
Eslint Plugin Node
Additional ESLint's rules for Node.js
Stars: ✭ 740 (-68.36%)
Mutual labels:  npm, npm-package, npm-module
Rando.js
The world's easiest, most powerful random function.
Stars: ✭ 659 (-71.83%)
Mutual labels:  npm, npm-package, npm-module
React Ckeditor
CKEditor component for React with plugin and custom event listeners support
Stars: ✭ 124 (-94.7%)
Mutual labels:  npm, npm-package, npm-module
Eslint Plugin Vue
Official ESLint plugin for Vue.js
Stars: ✭ 3,592 (+53.57%)
Mutual labels:  npm, npm-package, npm-module
Cpx
A cli tool to watch and copy file globs.
Stars: ✭ 394 (-83.16%)
Mutual labels:  npm, npm-package, npm-module
Darkreader
Dark Reader Chrome and Firefox extension
Stars: ✭ 12,052 (+415.26%)
Mutual labels:  dark-theme, darkmode, nightmode
Reactopt
A CLI React performance optimization tool that identifies potential unnecessary re-rendering
Stars: ✭ 1,975 (-15.56%)
Mutual labels:  npm, npm-package, npm-module
Webcam Easy
javascript access webcam stream and take photo
Stars: ✭ 79 (-96.62%)
Mutual labels:  npm, npm-package, npm-module
Package.json
文件 package.json 的说明文档。
Stars: ✭ 67 (-97.14%)
Mutual labels:  npm, npm-package, npm-module
Ngx Smart Modal
Modal/Dialog component crafted for Angular
Stars: ✭ 256 (-89.06%)
Mutual labels:  npm, npm-package, npm-module
Tplink Cloud Api
A node.js npm module to remotely control TP-Link smartplugs (HS100, HS110) and smartbulbs (LB100, LB110, LB120, LB130) using their cloud web service (no need to be on the same wifi/lan)
Stars: ✭ 96 (-95.9%)
Mutual labels:  npm, npm-package, npm-module
AndroidMultiTheme
一个对安卓应用支持多种主题的库,并可以不用重新创建Activity来动态切换主题。Android library support multi theme for app, and change theme dynamically without recreation of Activity.
Stars: ✭ 24 (-98.97%)
Mutual labels:  dark-theme, darkmode, nightmode
Npm Run All
A CLI tool to run multiple npm-scripts in parallel or sequential.
Stars: ✭ 4,496 (+92.22%)
Mutual labels:  npm, npm-package, npm-module
GithubDarkTheme
Dark Theme for Github
Stars: ✭ 60 (-97.43%)
Mutual labels:  dark-theme, dark, darkmode
Awesome Node Utils
some useful npm packages for nodejs itself
Stars: ✭ 51 (-97.82%)
Mutual labels:  npm, npm-package, npm-module
Turn-Off-the-Lights-Chrome-extension
Chrome extension
Stars: ✭ 81 (-96.54%)
Mutual labels:  dark-theme, darkmode, nightmode
Turn-Off-the-Lights-Firefox-extension-WebExtensions
Firefox extension (WebExtensions)
Stars: ✭ 19 (-99.19%)
Mutual labels:  dark-theme, darkmode, nightmode
Packagephobia
⚖️ Find the cost of adding a new dependency to your project
Stars: ✭ 1,110 (-52.54%)
Mutual labels:  npm, npm-package, npm-module
Event Target Shim
An implementation of WHATWG EventTarget interface, plus few extensions.
Stars: ✭ 89 (-96.19%)
Mutual labels:  npm, npm-package, npm-module

Darkmode.js

npm version npm downloads License Medium Badge Twitter: sandochee

🌓 Add a Dark Mode / Night Mode to your website in a few seconds

This library uses the CSS mix-blend-mode to bring Dark Mode to any of your websites. Just copy-paste the snippet and you will get a widget to turn on and off the Dark Mode. You can also use it without the widget programmatically. The plugin is lightweight, built-in Vanilla. It also uses local storage by default, so your last setting will be remembered!

I have been inspired by this article: https://www.aworkinprogress.dev/sun-moon-blending-mode

Features

  • Widget appears automatically
  • Saving users choice
  • Automatically shows Darkmode if the OS preferred theme is dark (if the browsers support prefers-color-scheme)
  • Can be used programmatically without widget

Demo

Check out the demo in these websites:

Wordpress plugins

If you are using Wordpress you may want to have a look at these plugins based on Darkmode.js:

Nuxt.js module

If you are using Nuxt.js there is a module for Darkmode.js:

📖 How to use

Darkmode.js is very easy to use, just copy-paste the following code or use the npm package.

🚀 Easy way (using the JSDelivr CDN)

Just add this code to your HTML page:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/darkmode-js.min.js"></script>
<script>
  function addDarkmodeWidget() {
    new Darkmode().showWidget();
  }
  window.addEventListener('load', addDarkmodeWidget);
</script>

📦 Using NPM

npm install darkmode-js

Then add the following JavaScript code:

import Darkmode from 'darkmode-js';

new Darkmode().showWidget();

⚙️ Options

Here are the option availables:

const options = {
  bottom: '64px', // default: '32px'
  right: 'unset', // default: '32px'
  left: '32px', // default: 'unset'
  time: '0.5s', // default: '0.3s'
  mixColor: '#fff', // default: '#fff'
  backgroundColor: '#fff',  // default: '#fff'
  buttonColorDark: '#100f2c',  // default: '#100f2c'
  buttonColorLight: '#fff', // default: '#fff'
  saveInCookies: false, // default: true,
  label: '🌓', // default: ''
  autoMatchOsTheme: true // default: true
}

const darkmode = new Darkmode(options);
darkmode.showWidget();

▶️ Methods

If you don't want to show the widget and enable/disable Darkmode programatically you can use the method toggle(). You can also check if the Dark Mode is activated with the method isActivated(). See them in action in the following example:

const darkmode =  new Darkmode();
darkmode.toggle();
console.log(darkmode.isActivated()) // will return true

Override style

  • A CSS class darkmode--activated is added to the body tag when the darkmode is activated. You can take advantage of it to override the style and have a custom style
  • Use the class darkmode-ignore where you don't want to apply darkmode
  • You can also add this style: isolation: isolate; in your CSS, this will also ignore the darkmode.
  • It is also possible to revert the Dark Mode with this style mix-blend-mode: difference;

Examples

.darkmode--activated p, .darkmode--activated li {
  color: #000;
}

.button {
  isolation: isolate;
}

.darkmode--activated .logo {
  mix-blend-mode: difference;
}
<span class="darkmode-ignore">😬<span>

Debug

If it does not work you may have to add the following code, but this will invalidate the classes to override.

.darkmode-layer, .darkmode-toggle {
  z-index: 500;
}

Browser compatibility

This library uses the CSS mix-blend-mode: difference; to provide the Dark Mode. It may not be compatible with all the browsers. Therefore the widget has been hidden in Internet Explorer and Edge. This library also uses prefers-color-scheme: dark to automatically enable the Dark Mode if the OS prefered theme is dark.

Check the compatibility here:

Development

  • yarn build or npm run build - produces a production version of your library under the lib folder
  • yarn dev or npm run dev - produces development version of your library and runs a watcher
  • yarn test or npm run test - it runs the tests :)
  • yarn test:watch or npm run test:watch - same as above but in a watch mode

⭐️ Show your support

Please ⭐️ this repository if this project helped you!

patreon.png

🍺 Buy me a beer

If you like this project, feel free to donate:

  • PayPal: https://www.paypal.me/kanbanote
  • Bitcoin: 19JiNZ1LkMaz57tewqJaTg2hQWH4RgW4Yp
  • Ethereum: 0xded81fa4624e05339924355fe3504ba9587d5419
  • Monero: 43jqzMquW2q989UKSrB2YbeffhmJhbYb2Yxu289bv7pLRh4xVgMKj5yTd52iL6x1dvCYs9ERg5biHYxMjGkpSTs6S2jMyJn
  • Motive: MOTIV-25T5-SD65-V7LJ-BBWRD (Get Motive Now: https://motive.network)

📄 License

MIT License

Copyright (c) Sandoche Adittane

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].