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

cookieyesno

v1.1.1

Published

![Cookiebanner Screenshot](screenshot.png)

Downloads

11

Readme

CookieYesNo

An easy to use GDPR-complient cookie-banner

Cookiebanner Screenshot

✅ GDPR-complient

✅ Easy to Use

✅ Mobile friendly

✅ Small memory footprint

✅ Highly customizable

Usage

The banner on the screenshot above has been created using only the 14 lines you can see below.

var cyn = new CookieYesNo({
  categories: {
    required: {
      name: 'Required cookies',
      description: 'These cookies are necessary for the website to function properly',
      accepted: true,
      changeable: false
    },
    analytics: {
      name: 'Web analytics',
      description: 'These cookies are used to analyze the user\'s behavior.'
    }
  }
});

Documentation

Configuration

The configuration is the only argument of new CookieYesNo(config) and is a map, The following things can / have to be configured:

  • categories (Map) Required » Take a look at the category configuration
  • text (Map) [optional] Link placeholders can be used
    • above (String) [optional] Text above the section where the user can select specific cookie-categories
    • below (String) [optional] Text below the section where the user can select specific cookies
  • title (String) [optional - by default "Cookie Settings"] Title of the banner
  • acceptAllButtonText (String) [optional - by default "Accept all cookies"] Text of the button that's for accepting all cookies
  • acceptSelectionButtonText (String) [optional - by default "Accept selected cookies"] Text of the button that's for accepting only selected cookie categories
  • privacyPolicy (Map) [optional]
    • url (String) URL of your privacy policy (in case the banner covers the link on the actual page)
    • text (String) Text of the link
  • cookiePolicy (Map) [optional]
    • url (String) URL of your cookie policy (String)
    • text (String) Text of the link
  • imprint (Map) [optional]
    • url (String) URL of your imprint (required in case that the banner covers the link on the actual page)
    • text (String) Text of the link
  • version (String) [optional] Version of the configuration - if you change the version - the user has to consent again (for the case that you change something in the categories) - Use any text you like to, I recommed the date of the change. If not version has been set before, the user also give his consent again.

Category configuration

Each cookie category is an item in the categories-Map. Here a short example:

categories: {
  required: {
    name: 'Required cookies',
    accepted: true,          // preselected
    description: 'These cookies are necessary for the website to function properly.',
    changeable: false       // user can not change this option
  },
  analytics: {
    name: 'Web Analytics',
    description: 'These cookies are used to analyze the user\'s behavior.'
  }
}

Configuration possibilities of a category

  • name (String) Required Name/Title of the cookie category
  • description (String) Required Description of the cookie category
  • accepted (Boolean) [optional - by default false] If the category is preselected
  • changeable (Boolean) [optional - by default true] If the user can change the value
  • reloadOnReject (Boolean) [optional - by default true] If the page is reloaded if the cookie category gets rejected - We need to do this to stop scripts from running that would set cookies.
  • onAccept (Array) [optional - by default []] Shortcut for Events
  • onReject (Array) [optional - by default []] Shortcut for Events
  • onChange (Array) [optional - by default []] Shortcut for Events

Script blocking

Blocking external scripts

You have to replace src with data-cyn-src and have to set the type to text/plain. The data-cyn-require attribute specifies which cookie category has to be allowed to run the script. So analytics has to be the key of the Web Analytics category in the categories map.

<script type="text/plain" data-cyn-src="analytics.js" data-cyn-require="analytics"></script>

Blocking inline scripts

Caution: May not block the execution of the script in older Firefox versions! External script blocking (above) is safe to use as well as Events (below). Use these medthods instead. The type attribute has to be set to text/plain. The script will be executed when the category with the key analytics is allowed.

<script type="text/plain" data-cyn-require="analytics">
  // YOUR CODE HERE
</script>

Events

Note: the category argument in the methods below is the key of the specific category in the categories map in the configuration map.

onAccept(category, callback)

Callback function gets executed when the specified category gets acceped.

onReject(category, callback)

Callback function gets executed when the specified category gets rejected. Explicitly return false if you don't want to reload the site. This can also be done by the config. If you like to reload the page either return nothing or return true.

onChange(category, callback)

Callback function gets executed when the specified category gets changed. The first argument of the callback function is a Boolean that states if the category has been accepted (true) or rejected (false).

First the onChange callbacks are executed, then the scripts are activated if necessary and then onAccept and onReject callbacks are executed.

Other methods

getSettings()

Get the current cookie settings as a map.

reviewSettings()

Let the user review his consent.

show()

Show the cookie banner.

hide()

Hide the cookie banner.

Link placeholders

Link placeholders can be used in the text.above and text.below. Simply put PRIVACY_POLICY, COOKIE_POLICY, or IMPRINT in the String. These will be replaced with the matching links. Note: In order to use this feature you have to specify the links in the configuration.

Modify the banner

It's pretty simple: just use CSS-rules. The following classes are available:

  • .cyn-banner: main banner element
  • .cyn-categories: table containing the different cookie categories
  • .cyn-btn-save: save settings button
  • .cyn-btn-accept-all: accept all button

Based on https://github.com/rollup/rollup-starter-app and https://github.com/rollup/rollup-starter-lib (both MIT License) Take a look at LICENSE_ROLLUP_STARTER_APP and LICENSE_ROLLUP_STARTER_LIB.