tiaanduplessis/dont-go
Über uns
A small client-side library with zero dependencies to change the title and/or favicon of the page when it is inactive. :relieved:
EntwicklerwerkzeugeGemessener Sternzuwachs
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- -1
- in 1 month
- Verlauf wird gesammelt
Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.
README.md
Original
Table of Contents
About
Dont-go is a small client-side library with zero dependencies to change the title and/or favicon of the page when it is inactive. Include a default favicon in your webpage to enable favicon changes. Pages without one can still use title changes.
As Seen In
Install
Install with cdn
<script src="https://unpkg.com/[email protected]/lib/dont-go.umd.js"></script>
Load this script before calling window.dontGo(...). The UMD bundle exposes the browser global; lib/dont-go.js is the CommonJS entry for module loaders.
The CDN example is pinned to the published 1.1.1 release. This README also describes unreleased changes on master: support for pages without a favicon, favicon arrays, cleanup functions, and improved lifecycle handling. These need a new release before they are available from npm or the CDN.
Install with npm
$ npm install dont-go
Install with yarn
$ yarn add dont-go
Usage
To use, simply call the function with options.
dontGo({
title: 'Alternative title text right here!',
faviconSrc: 'path/to/Alternative/favicon.ico',
timeout: 5000 //5 seconds
});
The faviconSrc property is optional and will keep the same icon if not set. It accepts a single URL or an array of URLs.
The timeout property is optional. It delays the first title and favicon change by the given number of milliseconds.
Set title, faviconSrc, or both to arrays to rotate through their values. Both advance on the same interval (1000 milliseconds by default), wrapping independently if their lengths differ. The first values appear as soon as the page becomes hidden, or after timeout if set:
dontGo({
title: ['Alternative title text', 'Another alternative title'],
faviconSrc: ['path/to/Alternative/favicon.ico', 'path/to/Alternative/favicon2.ico'],
interval: 1000 //1 second
});
Returning to the page cancels pending changes and restores the original title and favicon. The next hidden period starts at the first values again. Empty arrays leave that property unchanged, and non-string entries are ignored. An empty favicon URL is ignored. Changes follow the Page Visibility API; focus or blur alone does not trigger them.
Calling dontGo again replaces the previous configuration. It also returns a cleanup function for use when unmounting a component or stopping the effect:
const stop = dontGo({ faviconSrc: ['one.ico', 'two.ico'] });
// Restore the originals and remove the visibility listener and timers.
stop();
Demo
Check out the demo here.
Examples
Please see the example directory for more usage examples.
Contributing
Run npm test for lint, DOM regression tests, and an offline plain-script UMD smoke test (Node.js 18 or newer), then npm run build to regenerate the CommonJS, ES module, and UMD bundles. Rerun npm test after building to check the generated UMD bundle.
All Contributions are welcome! Please open up an issue if you would like to help out. :smile:
License
Licensed under the MIT License.
Icons made by Madebyoliver from www.flaticon.com is licensed by CC 3.0 BY.
Ähnliche Projekte entdecken
Wird geladen…