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

noise-to-scroll

v1.0.4

Published

A JavaScript library for browsers that allows users to scroll by making noise with their microphones.

Downloads

6

Readme

noise-to-scroll

A JavaScript library for browsers that allows users to scroll by making noise with their microphones.

This library uses the Web Audio API (see https://developer.mozilla.org/fr/docs/Web/API/Web_Audio_API).

Image from Gyazo

Installation

npm install noise-to-scroll

Usage

CDN

<html>
  <head>
    ...
  </head>
  <body>
    ...
    <script src="https://unpkg.com/noise-to-scroll/dist/noise-to-scroll.min.js"></script>
    <script>
        noiseToScroll({scrollableContainer: document.querySelector('#myScrollableElement')})
            .start()
            .then(() => {
                console.log('make some noise to scroll!');
            });
    </script>
  </body>
</html>

With a module bundler

import { nts } from 'noise-to-scroll'; // es6 import style or basic require

nts({scrollableContainer: document.querySelector('#myScrollableElement')})
    .start()
    .then(() => {
        console.log('make some noise to scroll!');
    });

This library is also compatible with AMD loading.

The minified javascript file in the /dist folder is built with webpack with libraryTarget set to umd (see https://webpack.js.org/configuration/output/#outputlibrarytarget).

API

Constructor noiseToScroll({options})

The options parameter is not required and has default values.

| param | type | default | detail | |---------------------|-------------------------|-------------------------------------------|-----------------------------------------------------------------------------------------------------------------------| | scrollableContainer | HTMLElement|Object | window | The HTML element (or object) that is scrollable, the method .scrollBy({options}) will be used on it for the scroll. | | scrollMethod | String | scrollBy | Method called on the scrollableContainer. | | scrollTop | Number|Function | window.innerHeight * 0.65 | Value of the top scroll. | | scrollLeft | Number|Function | 0 | Value of the left scroll. | | scrollBehavior | String|Function | smooth | Behavior of the scroll. | | scrollOptions | Object|Function | {scrollTop, scrollLeft, scrollBehavior} | Option object passed to the scrollMethod method. | | scrollDebounce | Number | 100 | Number of milliseconds passed on the debounce for the scroll function. | | debug | Boolean|String | false | Enable debug logs, can also pass the method to call on the console object (console[debug]). | | clipLag | Number | 150 | Number of milliseconds of timeout after the end of a detected noticeable noise. | | clipLevel | Number | 0.8 | Level of 'volume' on which the scroll event will trigger. 0 < clipLevel < 1 | |

start()

Returns a Promise that is resolved if the browser supports the mediaDevices, AudioContext and if the user accepts to allow microphone on the web page.

Rejected if unsupported or user denied to allow microphone.

The Promise might not be resolved or rejected if the user doesn't answer the permission popup.

noiseToScroll()
    .start()
    .then(() => {
        console.log('browser support OK and user allowed microphone access'); // noiseToScroll is up and running
    })
    .catch((error) => {
        console.log(`unable to start noiseToScroll: ${error}`); // error contain the reason
    )};

detect()

Returns a Promise that is resolved if the browser supports mediaDevices and AudioContext.

Rejected if unsupported.

noiseToScroll()
    .detect()
    .then(() => {
        console.log('browser support OK'); // ready to start
    })
    .catch((error) => {
        console.log(`browser doesn't support: ${error}`);
    )};

on('event', listener)

Listen to the following events :

  • clipping : fired when a noise becomes noticeable according to clipLevel, no debounce, event is fired 100 times each seconds, listen carefully!
  • scroll : fired every time the scrollBy method is called on the scrollableContainer.
  • noise : similar to scroll event but the first param passed to the listener is the 'volume' that triggered the scroll.

.on() methods can be chained.

noiseToScroll()
    .on('noise', (volume) => {
        console.log(`volume ${volume} triggered the scroll!`);
    });