Giter Site home page Giter Site logo

kytta / shareon Goto Github PK

View Code? Open in Web Editor NEW
454.0 4.0 24.0 1.47 MB

📯 Lightweight, stylish, and ethical share buttons for popular social networks

Home Page: https://shareon.js.org/

License: MIT License

JavaScript 51.87% CSS 22.93% HTML 25.20%
sharing share-buttons javascript

shareon's Introduction

Shareon

Shareon logo — the Postal Horn emoji

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.

Shareon demo screenshot

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

shareon's People

Contributors

amiceli avatar andersonjoseph avatar andybalaam avatar beedward avatar dependabot[bot] avatar dourosdimitris avatar kabszac avatar kytta avatar matthew-e-brown avatar pre-commit-ci[bot] avatar realorangeone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

shareon's Issues

css file not minified

Good day,
file shareon.min.css released within 1.4.4 version is not minified.
Regards,
Krzysztof Kosz.

Opening share content inline instead of new window/tab?

hello nick

we like your plugin and are considering working with it. could you please share your opinion on the following:

current shareon behaviour

  • klick a share button
  • new window/tab is opened with preloaded share-content (user leaves current page / context)

desired shareon behaviour

  • klick a share button
  • inline element (e.g. div or iframe) is populated with preloaded share-content (user stays on current page)

is this impossible/restricted by CORS policies or other technical reasons?

thank you

ps.: i understand that is currently not part of shareon's features, just asking if you think this could be possible.

Add ability to choose the share2fedi instance

The Mastodon button (in the future this should become the Fediverse button) currently redirects to my instance of Share2Fedi (aka toot). This is fine now, but with the usage of Shareon (and my S2F instance) rising, I am not sure that Vercel will be okay with the amount of traffic.

We need to add the data-s2f-instance or similar to the Mastodon button, where one can put the domain name where the instance is hosted.

See also: kytta/share2fedi#38

Add 'Print' button

Printing is also a valid form of sharing, especially for text-heavy pages, like blogs

Enforce PNPM a bit more

  • add PNPM to the prerequisites in the contributing guide
  • add other package managers' lock files to .gitignore

Add Fediverse button

Add a new button fediverse that would lead to Share₂Fedi. The mastodon button will stay, but is deprecated

Add "Share" button [sic]

On supported devices (which includes mobile browsers, Chromium and Edge on Windows, and Safari), there is the Web Share API. In particular, navigator.share() allows for showing a share popup of the OS, allowing to share the link to other apps we might not support: SMS messengers, Mastodon clients, etc. One can use navigator.canShare() to hide the button on unsupported devices.

  • pick an icon
  • implement method, similar to how "Copy URL" works

Automate icon creation process

The current icon creation process is a bit too complicated:

  • take icon from simpleicons.org
    • if the icon not present there, use icon from elsewhere (usually the owner)
      • in this case, make sure the icon is monochrome
  • resize the icon to 24×24px
  • optimize using https://github.com/RazrFalcon/SVGCleaner and https://github.com/svg/svgo
    • make sure it didn't break the icons
  • the resulting SVG file should have viewBox="0 0 24 24" and no width/height property
  • add fill="#fff" on the root <svg> tag and remove fill attribute from elsewhere
  • reorder <svg>'s attributes; it basically should always be equal to this: <svg fill="#fff" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
    • many put the xmlns first, so let's consider changing this of all icons
    • sometimes fill-rule attribute is needed (see Reddit); in this case it should be on individual <path> elements after the d attribute
  • put icon into https://yoksel.github.io/url-encoder/ with ‘External quotes: double’
    • here you can make sure the icon looks the way it should. Use black background in ‘Preview’ since the icon should be monochrome white
  • copy the string from ‘Ready for CSS’, excluding background-image: url( and );

I usually do it by hand, but others may not want to go such lengths. The process should be automated.

add linkedin icon

It would be nice to add LinkedIn share button. LinkedIn share url looks like:
https://www.linkedin.com/shareArticle?url=https%3A%2F%2Fhttps://shareon.js.org/%2F&mini=true

and the svg path converted from Likely to 24x24 viewport is below:
data:image/svg+xml;charset=utf-8,%3Csvg fill='%23fff' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.6,9L7.2,9L7.2,20.4L3.6,20.4L3.6,9ZM5.4,3.3C6.6,3.3 7.5,4.2 7.5,5.4C7.35,6.45 6.45,7.5 5.4,7.5C4.2,7.5 3.3,6.45 3.3,5.4C3.3,4.2 4.2,3.3 5.4,3.3M9.3,9L12.75,9L12.75,10.5C13.5,9.3 14.85,8.7 16.2,8.7C19.8,8.7 20.4,11.1 20.4,14.1L20.4,20.4L16.8,20.4L16.8,14.85C16.8,13.5 16.8,11.85 15,11.85C13.2,11.85 12.9,13.35 12.9,14.85L12.9,20.55L9.3,20.55L9.3,9ZM19.5,0L4.5,0C1.5,0 0,1.5 0,4.5L0,19.5C0,22.5 1.5,24 4.5,24L19.5,24C22.5,24 24,22.5 24,19.5L24,4.5C24,1.5 22.5,0 19.5,0Z'/%3E%3C/svg%3E

Background color is #1576B2 in hex.

Many thanks. If that would be easier I can try to prepare pull request.

Dynamic url not working

Whenever I am passing a URL with dynamic endpoints it is taking the current page url . How to use dynamic urls in the data-url attribute ?

Add customization techniques to the docs

shareon can be customizable — users can change icons' text colour, size, shape, etc. Users can also use shareon's style backend to create custom icons (see #6 as an example for GitHub). It would be nice to have a more thorough guide on how to do it.

Update Mastodon branding

Mastodon have been rocking a new-ish logo and a new colour (purple instead of blue), let's change the button for it as well.

  • update shareon.css
  • test the appearance
  • release as patch

Make icons follow the same pattern

Currently, all the icons in shareon are encoded a bit differently: they have different viewBoxes, different sizes, and the fill attribute is located in different places. If all the icons will have the same structure:

<svg fill='#fff' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='...'/></svg>

the CSS will probably take less space due to the more optimal GZIP compression.

Comparison to Likely

Hi!

I'm trying to understand the differences with Likely and I created the following comparison table.

Is there anything I have forgotten or anything I filled wrong?

Would it make sense to add such a table to the README? I would be happy to create a pull request if this makes sense.

(as of 2024/01/22)

Feature / Supported Network Shareon Likely
GitHub Stars 447 397
GitHub Forks 24 62
Last Update 2024/01/20 2023/12/23
Size 6KB 19KB
Logo Use Vector Logos [Needs Info]
Activity Level High Moderate
Facebook Supported Supported
LinkedIn Supported Supported
Mastodon Supported Not Supported
Messenger Supported (Requires FB App ID) Not Supported
Odnoklassniki Supported Supported
Pinterest Supported Supported
Pocket Supported Not Supported
Reddit Supported Supported
Teams Supported Not Supported
Telegram Supported Supported
Tumblr Supported Not Supported
Twitter Supported Supported
Viber Supported Supported
VK Supported Supported
WhatsApp Supported Supported
Copy URL Button Supported Not Supported
Email Share Button Supported Not Supported
Print Button Supported Not Supported
Extra Parameters URL, Title, Media, Text, Via, Hashtags URL, Title, Quote, Hashtag, ImageURL
Themes and Sizes [Needs Info] Supported
Automatic Counter Support Not Supported Supported
Other Features Configurable, WordPress Plugin Open Graph Protocol, Custom Buttons, Light/Dark Themes

Best,

Diego

Fix Messenger button not working with hardcoded `app_id`

Sharing via Messenger button seems to be broken due to hardcoded Facebook app_id property.
If you try to share any url via Messenger there will be always an error page.
Maybe add data atribute with custom app_id?

<a class="messenger" data-key="<custom_app_id>"></a>

Add Tumblr button

As per the title: Add the button that allows one to share the URL on Tumblr.

Refactor URL builder

As discovered while trying to implement a new parameter, our URL building is not ideal. In this particular case, we URL-encode stuff twice: when we pass parameters to the builder and then in the builders themselves.

Most share pages use URL parameters, so wouldn't it be better for each social network to only define its main URL along with the needed parameters? Then, we can take the built-in URL and URLSearchParams to build the final URL.

A while ago, Dario did a similar thing, also adding a lot of other stuff. Since then, Shareon lost TypeScript, switched bundlers, heck, even the default branch is different. It might make more sense to re-implement this.

It is very important that the final size remains as small as possible, ideally under 1 kB for the ESM bundle. Use pnpm test to build and test for size. See also #62

LinkedIn share does not work in the apps

I integrated shareon.js (https://giddysouls.com/category/mushroom-supplements/mushroom-supplements.html) which works great for most except the LinkedIn button just takes me to the home page at LinkedIn. I noticed the same behaviour on the LinkedIn shareon.js home page button.

Update: Share seems to work fine on the desktop - creates a post in Linkedin in a browser tab. My issue above was observed on an Android phone with a Linkedin app installed. In which case, it opens the app but the share isn't present. Share works fine with WhatsApp, Reddit apps installed on the same phone.

Automatically build and deploy documentation

Instead of manually generating and pushing the documentation to the pages branch, let's put the docs sources in the repo, use Vite to build them and upload them to the GH Pages

CSS not exported from package

Hi,
I am trying to use shareon within a Webpack project, but I cannot import the styles, I get an error:

Package path ./dist/shareon.min.css is not exported from package /project/node_modules/shareon (see exports field in /project/node_modules/shareon/package.json)

My workaround is to import the styles from cdn, but I am wondering if the package exports can be updated in a future revision.

Thanks!

Describe the `document.navigator` security caveats in the docs

Thanks for building this awesome tool.

I was trying to use it in one of my projects, I am using Vite to build the project.

I added the CSS and used the following code for JS.

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

After that all the buttons worked, but copy-url throws an error when I click on that button. Even after initialization, it shows a warning ReferenceError: temp0 is not defined. The error

TypeError: navigator.clipboard is undefined
    u https://cdn.jsdelivr.net/npm/shareon@2/dist/shareon.es.js:27
    u https://cdn.jsdelivr.net/npm/shareon@2/dist/shareon.es.js:25
    <anonymous> http://localhost/products/123:417

I am testing from Firefox, I would like to mention that your demo at shareon.js.org/ works fine from the same browser.

Can you please help me to find and fix the issue?

Legacy browser support

We are still on 1.6.3, any reason why 2.x branch doesn't use vite legacy plugin to support older browsers?

Add contribution guidelines

To ease the contribution process contribution guidelines should be written, which explain all important processes; most importantly — addition of new icons.

No IE11 Support with 1.4.1 — transpilation missing

Hello,

We use shareon, but also need to support IE11. 1.3.1 worked great in IE11, but after upgrading to 1.4.1, we receive a syntax error due to the use of an error function here:

var urlBuilderMap = {facebook:(d) => ...

Is it possible to continue having the dist JS be compiled to es5 for IE11 support? For now, we have to roll back to 1.3.x.

Thank you
Brandon

Add 'Email' button

I swear I had someone ask me for this a long time ago. The button should redirect to a mailto: URL. I'll have to think about how to build the message body and what to put in the title

Support for X logo rather than Twitter?

Hello,

Hope you are well and thanks for this great library.

One question I have had sent to me recently is whether we should continue to use the Twitter logo or switch to X. It would be great if shareon could support both?

Is this a possibility?

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.