🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

favicon-switcher

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

favicon-switcher

Switch page favicons using media queries

1.2.2
latest
Source
npm
Version published
Weekly downloads
27
-42.55%
Maintainers
1
Weekly downloads
 
Created
Source

Favicon Switcher

Live preview

Light mode favicon example Dark mode favicon example

Switches site's favicon by matching media queries. It could be used for light/dark mode switching. Due to browsers don't support all Media Query features in link tag, this module fixes it.

Usage

Script doesn't require any setup or configuration and works like a polyfill. The example below shows how to make dark/light mode icon switching.

Use the main library to automatically turn icon switching on:

<script src="https://unpkg.com/favicon-switcher@1.2.2/dist/index.js" crossorigin="anonymous" type="application/javascript"></script>

If you need more control to turn switching on and off use one of the next module:

UMD

Use with UMD:

<script src="https://unpkg.com/favicon-switcher@1.2.2/dist/index.umd.js" crossorigin="anonymous" type="application/javascript"></script>
<script>faviconSwitcher()</script>

ESM

Use as ES module:

<script type="module" language="javascript">
  import initSwitcher from 'https://unpkg.com/favicon-switcher@1.2.2/dist/index.esm.js'

  // Subscribe to media queries changing events
  const unsubscribe = initSwitcher()
  // Unsubscribe later on some condition. For example on page navigation.
  unsubscribe()
</script>

Complete example

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <link rel="icon" media="(prefers-color-scheme:dark)" href="favicon-dark.png" type="image/png" />
    <link rel="icon" media="(prefers-color-scheme:light)" href="favicon-light.png" type="image/png" />
    <script src="https://unpkg.com/favicon-switcher@1.2.2/dist/index.js" crossorigin="anonymous" type="application/javascript"></script>
  </head>
  <body></body>
</html>

License

MIT © Rumkin

Keywords

web

FAQs

Package last updated on 17 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts