Skip to content

A 1k script that adds `appearance-changed` event to detect OS theme changes

License

Notifications You must be signed in to change notification settings

orca-scan/appearance-changed-event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

appearance-changed-event

A 1k script that adds appearance-changed event to detect OS theme changes

Usage

Add appearance-changed-event.min.js to your page and start listening for appearance-changed event.

// fires every time the OS theme changes
window.addEventListener('appearance-changed', function(e) {
  console.log(e.detail); // `light`, `dark`
});

Also adds window.appearance which you can use to get the current OS theme:

switch (window.appearance) {
    
    case 'light': {
       // do some light theme stuff
    } break;

    case 'dark': {
       // do some dark theme stuff
    } break;
}

Development

The project includes a node server, run the following then visit http://localhost:8080

git clone https://github.com/orca-scan/appearance-changed-event
cd appearance-changed-event
npm install
npm start

Update .min files

To create a new version of the minified appearance-changed-event.min.js file from source, tweak the version number in package.json and run npm run build

History

For change-log, check releases.

License

Licensed under MIT License © Orca Scan (build a barcode scanner app without code)

About

A 1k script that adds `appearance-changed` event to detect OS theme changes

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published