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

shareon

v2.5.0

Published

Lightweight, stylish and ethical share buttons for popular social networks

Downloads

1,634

Readme

Shareon

Lightweight, stylish, and ethical share buttons

  • Small. Dependency-free. CSS+JS bundle is only 6 KB minified and brotlied.
  • Stylish. Uses official vector logos and colours with no visual mess.
  • Ethical. Embeds no tracking code. JS is required only for the setup.

See the live demo at shareon.js.org

Install

Simply load the needed files from the CDN:

<link
  href="https://cdn.jsdelivr.net/npm/shareon@2/dist/shareon.min.css"
  rel="stylesheet"
/>
<script
  src="https://cdn.jsdelivr.net/npm/shareon@2/dist/shareon.iife.js"
  defer
  init
></script>
  • defer makes sure Shareon is loaded after HTML is parsed
  • init will automatically initialize Shareon buttons

Do not auto-initialize

Remove the init attribute and initialize Shareon when you need it:

<script
  src="https://cdn.jsdelivr.net/npm/shareon@2/dist/shareon.iife.js"
  defer
></script>

<script>
  // do something
  Shareon.init();
</script>

Use ESM build

There is also a ESM build for the browsers, which doesn't support auto-initialization:

<script type="module">
  import { init } from "https://cdn.jsdelivr.net/npm/shareon@2/dist/shareon.es.js";
  // do something
  init();
</script>

Bundle with Node

You can also install Shareon using your favourite package manager and include it in your source files:

pnpm add shareon  # or `npm install`, or `yarn add`
import { init } from "shareon";
import "shareon/css"; // most bundlers will transpile this CSS

init();

CommonJS imports are also supported:

const Shareon = require("shareon");
require("shareon/css"); // most bundlers will transpile this CSS

Shareon.init();

Usage

Create a container with class shareon and populate it with elements, class names of which match the names of the social networks (or copy-url, for the 'Copy URL' button, or print for the 'Print' button):

<div class="shareon">
  <a class="facebook"></a>
  <a class="fediverse"></a>
  <a class="linkedin"></a>
  <a class="mastodon"></a>
  <!-- FB App ID is required for the Messenger button to function -->
  <a class="messenger" data-fb-app-id="0123456789012345"></a>
  <a class="odnoklassniki"></a>
  <a class="pinterest"></a>
  <a class="pocket"></a>
  <a class="reddit"></a>
  <a class="teams"></a>
  <a class="telegram"></a>
  <a class="tumblr"></a>
  <a class="twitter"></a>
  <a class="viber"></a>
  <a class="vkontakte"></a>
  <a class="whatsapp"></a>
  <a class="copy-url"></a>
  <a class="email"></a>
  <a class="print"></a>
</div>

Shareon will populate these <a> elements with correct href attributes.

Use with <button>s

You can use <button> (or any other element) instead of <a>s. In this case, Shareon will create an onclick-listener for each button. I do not recommend doing this, as this is not so good for semantics.

Share metadata

By default, the URL and the title of the active page will be shared. You can customize it with data- attributes. These can be applied on a specific button or on the whole .shareon container:

<div class="shareon" data-url="https://custom.url/for-this-page">
  <a class="facebook" data-title="Custom Facebook title"></a>
  <a class="twitter" data-title="Custom Twitter title"></a>
</div>

Apart from the URL and title, some networks support extra parameters:

  • you MUST add data-fb-app-id to the FB Messenger button to make sharing even possible
  • add data-s2f-instance to the Fediverse button to set your Share₂Fedi instance
  • add data-media to an Odnoklassniki, Pinterest, or VK button to customize the pinned picture
  • add data-text to a Mastodon, Telegram, Tumblr, Viber, or WhatsApp button to add custom message text
  • add data-via to a Mastodon, Tumblr, or Twitter button to mention a user
  • add data-hashtags to a Facebook, Tumblr, or Twitter button to include hashtags in the shared post.
    • should be a comma-separated string, for example stuff,tech,buttons
    • Twitter & Tumblr support multiple hashtags
    • Facebook only supports a single hashtag; only the first one will be used

Here are all custom parameters:

<div class="shareon" data-url="https://custom.url/for-this-page">
  <a class="facebook" data-title="Custom Facebook title" data-hashtags="awesome"></a>
  <a class="fediverse" data-s2f-instance="s2f.mydomain.example"></a>
  <a class="messenger" data-fb-app-id="0123456789012345"></a>
  <a class="pinterest" data-media="https://custom.picture/for-pinterest">Pin</a>
  <a class="telegram" data-text="Check this out!"></a>
  <a class="tumblr" data-hashtags="nice,buttons" data-text="These are some nice buttons" data-via="myblog"></a>
  <a class="twitter" data-via="MyNickname" data-hashtags="shareon,awesome,brilliant"></a>
  <a class="mastodon" data-via="@[email protected]"></a>
  <a class="whatsapp" data-url="https://custom.url/for-whatsapp">Send</a>
</div>

Other versions

Licence

Copyright © 2020–2022 Nikita Karamov
Licenced under the MIT License.

Shareon was heavily inspired by Likely, and has a somewhat backwards-compatible API (excluding themes and sizes). Likely is licenced under the MIT License.

Shareon's logo is the Postal Horn emoji from Noto Emoji. Noto Emoji is licenced under the Apache License v2.0.

Share icons are being sourced from Simple Icons. Simple Icons is released under CC0, but the icons themselves may be subject to copyright of the respective owners.


This project is hosted on GitHub: https://github.com/kytta/shareon