npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nightly.js

v2.0.1

Published

A zero dependency javascript library that enables the night mode in your website easily

Downloads

22

Readme

Nightly.js

GitHub license dependencies Status npm version Open Source Helpers

A zero dependency Javascript library for enabling dark/night mode in you UI.

Usage

  1. Include Nightly.js
  • Via <script/> tag

    <!-- Download this repository then use "dist/nightly.min.js" -->
    <script src="nightly.min.js"></script>
    
    <!-- Or use CDN -->
    <script src="https://cdn.jsdelivr.net/gh/fcmam5/[email protected]/dist/nightly.min.js"></script>
  • Or if you prefer npm:

    npm install --save nightly.js

    Then include it

    var Nightly = require('nightly.js');
  1. In you main Javascript file initiate the object

    • Using default Parameters with persistence disabled:

      var Nightly = new Nightly();
    • Or can customize your parameters

      The first parameter is to customize default settings and the second is to enable persistence

      var nightModeConfig = {
        body: 'backgorund color', // Default: #282828
        texts: 'texts color', // Default: #f5f5f5
        inputs: {
          color: 'text color inside inputs', // Default: #f5f5f5
          backgroundColor: 'background color', // Default #313131
        },
        buttons: {
          color: "button's text color", // Default: #f5f5f5
          backgroundColor: "button's backgournd color", // #757575
        },
        links: 'links color (normal state)', // Default: #009688
        classes: [
          // Classes to apply when enabling the dark mode on certain elements
          {
            apply: 'my-selected-class', // just the class name (without the .)
            to: '.my-dark-class-to-the-selected-class .some-nested-class', // uses querySelectorAll
          },
          {
            apply: 'another-selected-class',
            to:
              '.another-dark-class-to-the-selected-class.some-class .some-nested-class',
          },
        ],
      };
      
      var Nightly = new Nightly(nightModeConfig, true); // To disable persistence, set false instead of true
  2. Call the darkify() or the toggle() function

// To enable the dark mode
Nightly.darkify();

// To disable the dark mode
Nightly.lightify();

// Toggle between dark and light mode
Nightly.toggle();
  • You can also pass callbacks to darkify(), lightify(). And toggle() takes two callbacks (enableDarkModeCallback, enableLightModeCallback), for example:
var sayGoodMorning = function () {
  console.log('Good morning !');
};

var sayGoodNight = function () {
  console.log('Good night!');
};

// Pass sayGoodMorning() as callback to darkify
Nightly.darkify(sayGoodMorning);

// toggle() takes two callbacks (darkifyCallback, lightifyCallback)
Nightly.toggle(sayGoodNight, sayGoodMorning);

Example

In our first example we created a simple page as the following:

<style media="screen">
  body {
    padding: 50px;
  }
  #btn {
    height: 50px;
    width: 150px;
  }
  .red-text {
    color: #d32f2f;
  }
</style>

<h1>
  Hello, world <span class="red-text">!</span>
  <button type="button" name="button" id="btn">Toggle</button>
</h1>

<p>Please, <a href="#">Click here</a></p>

<div id="form-container">
  <form>
    <label for="name">Your name</label>
    <input type="text" name="name" value="Hello world" placeholder="name" />
  </form>
</div>

Then The result was as the following:

Before using Nightly.js

We included nightly.js just before closing the body tag, we initiate Nightly object with no arguments, then we set an event listener to a button to execute our toggle() method, that switches between darkify() and lightify()

<script src="../src/nightly.js" charset="utf-8"></script>
<script type="text/javascript">
  // Persistence disabled
  var Nightly = new Nightly();
  document.getElementById("btn").addEventListener("click", function(){
    Nightly.toggle();
  });

</script>
</body>

The result was as the following:

After using Nightly.js

TODO

  • [x] Add state persistence: use localstorage
  • [ ] Add supported browsers section after testing it
  • [ ] Improve usage section
  • [ ] Document and refactor the code
  • [ ] Continue writing tests
  • [ ] Write plugins for frameworks like Bootstrap - [ ] Bootstrap - [ ] Foundation - [ ] Materialize

License

This project is licensed under the GNU GPL v3.0 License - see the LICENSE file for details