Alien Night Theme - A free Dark Theme for Discourse

:discourse2: Summary Discourse Alien Night is a dark focused clean theme with the Dark/Light toggle component in mind to enhance your forum!
:eyeglasses: Preview Preview on theme-creator.discourse.org
:hammer_and_wrench: Repository Link GitHub - B-iggy/alien-night-discourse-dark-theme: A night friendly dark Discourse theme - dark/light switcher inclusive
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Note: with the release 4.0.0 I redesigned/refactored the theme from ground up. It’s more contrast friendly, it uses CSS variables and is overall more slick.

Hi there :wave:
I want to share a free dark theme for discourse called “Alien Night”.
I made it for my server game community.

Since I have people from all over the world playing on my servers and reading the forum at any time I wanted to have a dark and a bright theme people can choose from. Especially the night one should be eye friendly in the night.

Implemented Dark/Light Mode Toggle

Even though the component is labeled as broken, it works in my theme, if you follow some guidelines:

  1. Make the Light theme selectable for your users

  2. Select the Dark color here ( /admin/site_settings/category/all_results?filter=dark%20m )

  3. Include the Dark-Light-Toggle component for this theme and check the box at the bottom:

If everything set correctly, you have on a right sidebar the Dark/Light Toggle:

Enjoy and let me know if you have any feedback or questions. :slight_smile:

Iggy

38 Likes

wow so cool!!!:+1:

1 Like

Very interested, share it please

6 Likes

Alright :smiley_cat:

Sorry in advance for not doing it the 100% professional way ( using custom js templates from discourse? ) but for now it works very good for me this way:

The main idea is basically to append a modifier class to the html DOM and nest the dark styles in proper way in the CSS and store the user choice in the local storage.

So my HTML looks like this:

<span class="theme-switcher">Switch Theme:</span>
  <a class="theme-switcher-attr theme-switcher-light" href="#">Light</a>
  <a class="theme-switcher-attr theme-switcher-dark" href="#">Dark</a>  

The theme switcher CSS and a snippet example with the modifier class

.theme-switcher-attr {
    color: #fff !important;
    font-weight: bold;
    padding: 5px;
    margin: 2px;
    display: inline-block;
}

.theme-switcher-light {
    background-color: #fff;
    color: #222 !important;
    border: 1px solid #333;
}

.theme-switcher-dark {
    background-color: #10161d;
    border: 1px solid #fff;
}

/*
CSS of the Dark Theme in combination with the modifier class from the theme switcher
 */
html.dark,
html.dark body {
    background-color: #10161d;
}

html.dark,
html.dark .top-navbar-links-title,
html.dark .nav-pills>li>a,
html.dark .topic-list a.title,
html.dark .topic-body .regular,
html.dark #topic-title h1 a,
html.dark #topic-title .topic-statuses,
html.dark .category-list tbody .category h3 a[href],
html.dark .timeline-container .topic-timeline .timeline-replies,
html.dark .discourse-no-touch .topic-body .actions .fade-out,
html.dark #suggested-topics,
html.dark .topic-list-bottom,
html.dark .user-main .nav-stacked li>a.active,
html.dark .theme-switcher,
html.dark div.poll li[data-poll-option-id],
html.dark aside.onebox header a[href],
html.dark .contents,
html.dark nav.post-controls button.create,
html.dark .directory .period-chooser,
html.dark .directory table,
html.dark .dashboard-stats table .title i.fa,
html.dark #topic-closing-info,
html.dark .content-list ul li a,
html.dark .topic-map .map .number, .topic-map .map i,
html.dark .topic-map h3,
html.dark .topic-map .buttons .btn:hover {
    color: #fff;
}

And the JS via async placed in the </head> customize field

<script async>
$(document).ready(function() {

    var darkTheme = localStorage.getItem("theme");

    if (darkTheme !== null){
        $('html').addClass('dark');
    }

    if (typeof(Storage) !== "undefined") {
        // Code for localStorage/sessionStorage.
        $('.theme-switcher-dark').on('click', function() {
            localStorage.setItem("theme", "dark");
            $('html').addClass('dark');
        });

        $('.theme-switcher-light').on('click', function() {
            localStorage.removeItem("theme");
            $('html').removeClass('dark');
        });

    } else {
        // Sorry! No Web Storage support..
        console.log('Upgrade to a better browser! Really!')
    }
});
</script>

I appreciate any feedback and for the complete package I updated the theme switcher also in Github and created an easy Release you can just download everything:

https://github.com/B-iggy/discourse-dark-theme/releases

14 Likes

It works perfectly, thanks @B-iggy!

3 Likes

@B-iggy I find a little bug
When you enter a topic (sometimes, not always) the link in navigation bar change in
https://forum.empyrion-homeworld.net/#
instead to e.g.
https://forum.empyrion-homeworld.net/t/griefing-and-cheating-report/3520

So, when you try to go in another page, or return to the home page (clicking the logo), the site is not responding.

Or the link does not match the title of the topic, e.g.


I need to press Ctrl and F5 to refresh all.

It also happens on my forum from yesterday, since I enabled the switcher themes.

Removing the strings href="#" in Html code seems to resolve the problems.
Can you try and confirm please?

2 Likes

After few days I can confirm that this bug is fixed by deleting href="#" from the Html code, e.g.

  <a class="theme-switcher-attr theme-switcher-light">Light</a>
  <a class="theme-switcher-attr theme-switcher-dark">Dark</a>

If anyone is interested I changed the position and shape of the buttons making them “fixed” on the page, so users can change from dark to light (or viceversa) without going back to top.

On CSS I add:

#top-navbar {
    position: fixed;
    top: 90px;
    left: 0;
    z-index: 90000;
    width: 70px;
    overflow: hidden;
    margin: 0;
    text-align: center;
    box-shadow: 0px 0px 4px #070708;
    border-radius: 0px 10px 10px 0px;
}

according to my Html code.

and this line (both here .theme-switcher-light and here .theme-switcher-dark) to make the round buttons
border-radius: 100%;

In Html/Top:

<div id="top-navbar">
  <span class="theme-switcher">Tema:</span>
  <a class="theme-switcher-attr theme-switcher-light"><i class="fa fa-sun-o fa-lg"></i></a>
  <a class="theme-switcher-attr theme-switcher-dark"><i class="fa fa-moon-o fa-lg"></i></a> 
</div>

I preferred to use the FontAwesome’s icons instead of a text for buttons.

3 Likes

Hey @Trash,

just today I got feedback from the community regarding this too so I wanted to tackle it. Thank you for your fix. Will try it out. Nice to see it in action by someone else :slight_smile:

1 Like

Thanks for the terrific theme and switcher. This is perfect for my astronomy club.

Question - the background of the header bar (I’m using the default bar for now) does not change color when the dark theme is selected. It stays at the default white. Can the script be modified to include changing the header?

Thanks,
Alan

You don’t need to modify the script, but add some lines on your css:

html.dark .d-header {
    background: #1c1c1c;  /*change it with the hex color you want*/
}

to change the background color

Instead, to change the color of the title (if you need) add somenthing like this:

html.dark .extra-info-wrapper .topic-link {
    color: #ffffff;  /*change it with the hex color you want*/
}
3 Likes

The lines for the header work perfectly. Thanks!

1 Like

Hi there @Trash and @B-iggy !

I’m trying to apply your brilliant dark theme with switch bar, but I’m afraid that I messed up something…
Dark theme is working, also I can se the switch buttons, but they are just not working… Also colour is fixed to white.

I’m not really sure where should I paste the HTML code (sorry about that, I’m greenhorn in that matter).
Should I put it in Head or Body? Or in all of it?


Thanks!

Hey @Pawel_Kosiorek,

glad you like my theme! :slight_smile:

You only showed the html code and I guess the CSS is right. But did you apply the JS also in the head?

This code here:

https://github.com/B-iggy/discourse-dark-theme/blob/master/alien-night-theme--theme-switcher.js

Needs to be put in the section (Common).
The HTML goes to the “After Header” for Desktop and Mobile independently since they are a bit different.

1 Like

Hi! Thanks for reply!
Now I can switch between Dark And Darker :smiley:
This is happening when I’m clicking to the moon:

And this is after click to the sun:

I think it’s related to naming of dark and light theme?

@B-iggy I would like to move this to the #plugin:theme , was wondering if you can orgnaise the the theme per:

5 Likes

Hello @sam

thank you very much for this opportunity - I feel honored :slight_smile:

I have reorganized all files and made it ready to use over native themes.
I updated / cleaned up everything and should be ready to go :slight_smile:

https://github.com/B-iggy/alien-night-discourse-dark-theme

Thanks again!

Iggy

5 Likes

Cool, moving this to the theme category please update the first post :full_moon_with_face:

4 Likes

Hi!
After your update everything works just fine! Congrats!
I found just one minor bug, from time to time switcher just stops working. There’s no effect when you’re trying to change from one to another theme. Site refresh helps.

One more thing, is it possible to change colour of top of the page and the switcher to night mode, when it’s switched to night mode :wink: Now it’s white on night mode.

Hey @Pawel_Kosiorek,

glad it worked with the native theme installation :slight_smile:
I will check why it is sometimes not working. Guess some internal JS call conflicts.

Yes, since I am using a background image for the header I left it accidentally white - will fix it.
Will adjust the color for the theme switcher too.

4 Likes

Love it!!!:kissing_heart:

1 Like