Darkmode bug chrome

Hey guys :slight_smile:

I attempted to deploy a Dark Mode following the advice on the community by @artur, from this code, which I inserted into the footer of my website. I don’t understand it doesn’t work

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

I get this error in Google Chrome Console

Uncaught ReferenceError: Darkmode is not defined at addDarkmodeWidget

Any ideas ? :last_quarter_moon:

Hi Lea,
Did you insert it in the custom code header, app level?
This is how it should look ( little button is created, see screenshot)

Found the issue: <https. < doesn’t have to be there (same at the end of the src")

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

Thanks @matthieu_chateau !

Any way to disable it just on modals windows?

You could try this one:

<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script>
<script>
  function addDarkmodeWidget() {
    if (window.location.href.indexOf('&viewMode=modal') === -1) {
      new Darkmode().showWidget();
    }
  }
  window.addEventListener('load', addDarkmodeWidget);
</script>

(sorry to respond to an ancient thread…)
This works great for our purposes! Are there ways to tweak settings in dark mode? There are some blocks that are pure black for example that I might like to be slightly lighter, or some text that could be different colors.

Thanks!

Hi,
There might be ways, but I haven’t looked into it as it is never requested by my clients. This dark mode comes from a library I haven’t checked in a long time.

No worries! My team is going to deal with it looking a little less than perfect.