Goodnight

A super small library for applying custom CSS styles at night.

Installation

The easiest way to install is by using Bower

$ bower install goodnight

…or you could download it and refer to it in your HTML like so:

<script src="/path/to/goodnight.min.js"></script>

Remember to put and use Goodnight in the head of your document to avoid a flash of unstyled content for the night version.

Usage

The following is the most basic example of using Goodnight with JavaScript:

Goodnight.css('styles/dark.css');

If you wanted to add more than one stylesheets, just use the css() method on each one.

Goodnight.css('styles/dark-layout.css');
Goodnight.css('styles/dark-colours.css');

This makes Goodnight search for dark.css in the styles directory and apply that from 6PM to 6AM. To set your own Goodnight times, use the AM and PM properties:

Goodnight.AM = 5; // 5AM
Goodnight.PM = 20; // 8PM

You can easily toggle light and dark styles using the toggle() method:

Goodnight.css('/path/to/dark.css');
document.querySelector('#some-button').addEventListener('click', function () {
	Goodnight.toggle(); // This removes styles from document.head
}, false);

Lastly, you can append a class to the body when it is nighttime like this:

Goodnight.class('my-night-class');

Adding multiple classes is possible as long as you seperate them using spaces.

Goodnight.class('my-first-night-class my-second-night-class');

Leaving out a class name will make it default to "goodnight".

License

Licensed under MIT. Created by Jared Cubilla.