包详细信息

shareon

kytta1.7kMIT2.6.0

Lightweight, stylish and ethical share buttons for popular social networks

share buttons, sharing, social networks

自述文件

Shareon

Shareon logo — the Postal Horn emoji

Lightweight, stylish, and ethical share buttons

  • Small. Dependency-free. CSS+JS bundle is 7.5 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.

Demo screenshot of all buttons Shareon supports

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="bluesky"></a>
  <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 Bluesky, 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="@MyNickname@myserver.social"></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

更新日志

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

2.6.0 - 2024-11-23

Added

Security

  • #122 Bump braces to v3.0.3
  • #135 Bump micromatch to 4.0.8
  • #136 Bump cross-spawn to v7.0.5
  • #137 Bump rollup to v4.27.2

Behind-the-scenes

  • #123 Use PNPM lockfile v9
  • #124 Update dev dependencies

2.5.0 - 2024-02-04

Added

2.4.0 - 2023-12-07

Added

  • #99 Email button
  • #100 Print button

Behind-the-scenes

  • #95 Update to Vite v5
  • #101 Enable automatic package publishing

2.3.0 - 2023-08-01

Added

Behind-the-scenes

2.2.3 - 2023-07-19

Fixed

  • v2.2.2 was published with the bug not fixed.

2.2.2 - 2023-07-15

Fixed

  • #71: Web Share icon got minified incorrectly, causing it to not show up at all. Fixed by Jake.

2.2.1 - 2023-07-15

Behind-the-scenes

  • #70: Icon minification and inlining happens automatically now. As a bonus, the CSS size went a bit down :)

2.2.0 - 2023-07-15

Added

Changed

2.1.0 - 2023-03-20

Added

Behind-the-scenes

2.0.2 - 2023-01-25

Changed

  • Sourcemaps are not being output any more
    • They're being loaded automatically and don't serve any other purpose. Disabling those helps us save a few bytes
  • Change minifier to esbuild (instead of terser)
    • This disables the minification of ESM, which is a good thing, because otherwise the file can't be tree-shaken properly
  • Shareon is now type: "module"
    • This doesn't change anything for the end users
  • Banner was removed
    • It took unnecessary bytes, and embedding it was somewhat buggy
  • Browserslist config now targets defaults
    • Opera 90 and Samsung Browser 17 aren't targeted. Shareon will still work on these browsers.
    • the previous config (using last 3 versions instead of last 2 versions) didn't change coverage that much

Behind-the-scenes

  • Updated to Vite v4
  • CSS is now bundled using Vite
    • this makes the build script leaner; it's still processed with PostCSS
  • Moved PostCSS and ESLint config to package.json

2.0.1 - 2023-01-23

Changed

  • Mastodon button updated to match the new style (#42)

2.0.0 - 2021-02-13

Added

  • BREAKING: new (auto-)init behaviour, inspired by petite-vue

    • require, import, or use <script> to include Shareon without initialization
    • use exported initializeShareon function in Node to initialize Shareon
    • use init attribute in script to initialize Shareon in-browser

      <script src="path/to/shareon.js" init>
  • CSS export for use in Webpack/Rollup/etc. (#35)

    import "shareon/css";
    require("shareon/css");

Changed

  • BREAKING: default version of the package doesn't auto-initialize buttons
  • BREAKING: instead of default export, named exports are now used. If IIFE is used, the global object's name is now Shareon, and it has one init() method
  • updated logos and colours for some social networks
  • removed mixins, defining the code/styles directly in the files
  • use Vite for building, reducing the devDependencies tree and build times drastically
    • BREAKING: newly built files offer worse browser support
  • change code style to Prettier

Removed

  • BREAKING: noinit version of the package is removed

1.6.3 - 2022-02-02

Changed

  • update URL for the toot instance
  • update URLs and usernames in metadata
  • update dev dependencies
  • migrate to PNPM

1.6.2 - 2021-06-29

Security

  • updated build dependencies

1.6.1 - 2021-01-17

Added

  • Add CHANGELOG as file

Fixed

  • Fix LinkedIn URL

1.6.0 - 2020-09-28

Changed

  • Add parameter for App ID for Messenger button (#17, #29)
    • now you have to include data-fb-app-id to your Messenger buttons

1.5.0 - 2020-09-24

Added

  • Add Mastodon button (#23, #27)

1.4.5 - 2020-09-22

Version 1.4.3 was skipped due to an error in the deployment process Version 1.4.4 is deprecated due to non-minified build files

Fixed

  • Fix transpilation for legacy browsers (#19, #21)
  • Fix <button>s not behaving correctly if there are <a>s further on the page
  • Fix PostCSS not applying any plugins (#22)

1.4.2 - 2020-09-18

Fixed

  • Fix WhatsApp button on desktop (#18, #20)

1.4.1 - 2020-08-01

Changed

  • move codebase from TypeScript to JavaScript+JSDoc
  • replace Sass with CSS+PostCSS

1.4.0 - 2020-07-30

Changed

  • Optimise code
    • package size got reduced down to 937 kb (.min.js) / 840 kb (.cjs/.mjs)
    • for loops were optimised to cut down execution time

1.3.1 - 2020-07-30

Fixed

  • Fix documentation

1.3.0 - 2020-07-26

Added

  • Add init() function to shareon (#11, #13)
    • this allows not only to postpone the initialization of shareon but also to re-run it

1.2.1 - 2020-07-12

Changed

  • Optimize icon SVG files to match one standard (#8)

1.2.0 - 2020-07-04

Added

  • Add LinkedIn button (#5)
  • Add Pocket button
  • Add Reddit button
  • Add Viber button

1.1.5 - 2020-06-26

Added

  • Add building to ESM

Changed

  • Update README and docs

Fixed

  • Fix unwanted border on <button> hover

1.1.4 - 2020-06-26

Changed

  • Rearrange fields in package.json
  • Change node-sass to sass
  • Update Rollup config
  • Update ESLint config

1.1.3 - 2020-06-25

Changed

  • Update dependencies

1.1.2 - 2020-03-30

Changed

  • Shorten the banner in JS and CSS files

Fixed

  • Fix inconsistent spacing between buttons

1.1.1 - 2020-03-27

Fixed

  • Fix incorrect spacing between button rows when wrapped

1.1.0 - 2020-03-27

Added

  • Add Odnoklassniki button
  • Add VK button

1.0.0 - 2020-03-26

Added

  • Add install instructions to README
  • Add usage instructions to README

1.0.0-beta.3 - 2020-03-26

Added

  • Add Facebook button
  • Add Messenger button
  • Add Pinterest button
  • Add WhatsApp button

Changed

  • Update colour of Telegram button
  • Rename shareon.css to shareon.min.css

Removed

  • Remove building to ESM

1.0.0-beta.2 - 2020-03-26

Fixed

  • Fix package files not being published to NPM

1.0.0-beta.1 - 2020-03-26

Initial release of shareon

Added

  • Add Telegram button
  • Add Twitter button