# Automatic Night Mode Plugin

**URL:** https://meta.discourse.org/t/automatic-night-mode-plugin/86174
**Category:** Feature
**Created:** [April 25, 2018, 7:37pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174 "2018-04-25T19:37:11Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![BlackKnob](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blackknob/32/93549_2.png) [@BlackKnob](https://meta.discourse.org/u/BlackKnob)
#### Post date: [April 25, 2018, 7:37pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/1 "2018-04-25T19:37:12Z")

</div>

Some users have been asking about automatic switching between a light and a dark theme. Could this be accomplished with a plugin?

I assume this would need two parts:

- a theme component with a javascript switching themes based on local time

- a Discourse plugin adding options to the user preferences page:  
turn night mode switching on/off, choose nighttime theme, set time nighttime time period

How difficult would it be to code? As in, how much would it cost?

---

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [April 25, 2018, 8:00pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/2 "2018-04-25T20:00:36Z")

</div>

That would be AWESOME!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 25, 2018, 11:32pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/3 "2018-04-25T23:32:34Z")

</div>

> [@BlackKnob](#):
>
> Could this be accomplished with a plugin?

With a plugin for sure, a bit harder to swing as a theme component.

If you reuse the logic in chronos by @j.jaffeux it will probably be not too hard. I would say 2 days of work if I had to pull out a number.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 2, 2019, 5:18am UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/4 "2019-02-02T05:18:01Z")

</div>

> [@sam](#):
>
> a bit harder to swing as a theme component.

Is this still the case today?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 2, 2019, 5:38am UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/5 "2019-02-02T05:38:22Z")

</div>

This can be done in a theme component these days

---

<div class="post-metadata">

### Author: ![mbcahyono](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mbcahyono/32/97721_2.png) [@mbcahyono](https://meta.discourse.org/u/mbcahyono)
#### Post date: [March 27, 2019, 12:22pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/6 "2019-03-27T12:22:24Z")

</div>

Is there any guide or example code to add editable user custom fields with a theme?

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [March 27, 2019, 2:04pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/7 "2019-03-27T14:04:46Z")

</div>

Why a theme when you can manage user fields in admin UI (`/admin/customize/user_fields`) itself?

---

<div class="post-metadata">

### Author: ![nexo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nexo/32/106384_2.png) [@nexo](https://meta.discourse.org/u/nexo)
#### Post date: [March 27, 2019, 3:51pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/8 "2019-03-27T15:51:13Z")

</div>

Until you find a solution, use this theme component as a placeholder: it’s for Macs. I know it’s not exactly what you need, but figured it may help.

> [@Dark Mode Automatic Theme Switcher](https://meta.discourse.org/t/dark-mode-theme-switch-for-safari-on-macos/112071):
>
> warning Discourse now supports [Automatic Dark Mode color scheme switching](https://meta.discourse.org/t/automatic-dark-mode-color-scheme-switching/161593) in core, this component is now deprecated and should no longer be used. [Repository](https://github.com/pmusaraj/discourse-dark-mode): https://github.com/pmusaraj/discourse-dark-mode Installation instructions: [Installing a theme or theme component](https://meta.discourse.org/t/how-do-i-install-a-theme-or-theme-component/63682)What this does? This component allows automatic switching to a dark theme when the browser is set to dark mode. This works for logged-in users only on all browsers that support the [prefers-color-scheme](https://caniuse.com/#feat=prefers-color-scheme) media query. By de…

---

<div class="post-metadata">

### Author: ![mbcahyono](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mbcahyono/32/97721_2.png) [@mbcahyono](https://meta.discourse.org/u/mbcahyono)
#### Post date: [April 1, 2019, 7:20am UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/9 "2019-04-01T07:20:44Z")

</div>

I mean to create custom user preference like time selector that can be saved with a theme. Is that possible these days?

With a plugin, I had to register the custom field as editable with `register_editable_user_custom_field` so it can be saved.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 1, 2019, 9:53pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/10 "2019-04-01T21:53:17Z")

</div>

I believe @pmusaraj was looking at this last.

---

<div class="post-metadata">

### Author: ![Anatolia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/anatolia/32/133777_2.png) [@Anatolia](https://meta.discourse.org/u/Anatolia)
#### Post date: [April 1, 2019, 10:15pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/11 "2019-04-01T22:15:59Z")

</div>

Is it possible to have a day - night switch on Discourse with a theme component?

 ![03e1af3d317a41a3cfe7434a2859b9f4](https://global.discourse-cdn.com/meta/original/3X/d/6/d6952b691fa88d34380353ac4582a4a463d38ee9.gif)

---

<div class="post-metadata">

### Author: ![Hanzo1](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@Hanzo1](https://meta.discourse.org/u/Hanzo1)
#### Post date: [April 3, 2019, 12:57am UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/12 "2019-04-03T00:57:38Z")

</div>

Need this for sure. Will be keeping an eye on this topic to see if anything updates.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [April 3, 2019, 12:52pm UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/13 "2019-04-03T12:52:30Z")

</div>

I don’t think we support custom user fields in themes at the moment. I do see the use case for them though, it’s nice to be able to ship a theme component with a user-configurable setting.

There is a fairly hacky workaround, to add a field in the UI only and then store the data in local storage or the session. That’s what I did on the experimental automatic dark mode switch for Safari, you can look at the code of that component to see how it’s done.

---

<div class="post-metadata">

### Author: ![mbcahyono](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mbcahyono/32/97721_2.png) [@mbcahyono](https://meta.discourse.org/u/mbcahyono)
#### Post date: [April 23, 2019, 4:27am UTC](https://meta.discourse.org/t/automatic-night-mode-plugin/86174/16 "2019-04-23T04:27:56Z")

</div>

I made a theme component for anyone who interested:

> [@Automatic Night Mode Component](https://meta.discourse.org/t/automatic-night-mode-component/115673):
>
> Following up the discussion here: I made a theme component that will automatically switch to night theme based on user preferences. It’s currently work on a per-browser basis. [Repository](https://github.com/muhlisbc/discourse-automatic-night-mode-theme) https://github.com/muhlisbc/discourse-automatic-night-mode-theme Screenshot: Installation Add this component to each theme installed. Known Issues I’ve received a report of the component making all navigation cause full reloads. Upon navigating between different pages …
