TopGit theo dõi sampotts/shr trên GitHub, đã đạt 150 sao. Simple, clean, and customizable social sharing buttons.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
The default share buttons used by the social networks are not only ugly to look at (sorry, they just are) but they usually depend on iframes, are slow and generally heavy. That led to me creating shr (short for share).
Features
Accessible - built using progressive enhancement
Lightweight - just 3KB minified and gzipped
Customisable - make the buttons and count look how you want with the markup you want
Semantic - uses the right elements. There's no <span>s as buttons type hacks
Fast - uses local storage to cache results to keep things fast
No dependencies - written in "vanilla" ES6 JavaScript
Changelog
Check out the changelog
Setup
To set up Shr, you first must include the JavaScript lib and optionally the CSS and SVG sprite if you want icons on your buttons.
1. HTML
Here's an example for a Facebook button, see HTML section below for other examples.
This markup assumes you're using the SVG sprite (which is optional) and the default CSS. If you're not using either of these then you can omit the shr__* classNames completely and the <svg>. The href attribute value is used to determine the type of network. It is also used as the fallback so must be valid.
Once Shr has been initialized on a button and data has been fetched, it is manipulated as below:
Note: Shr.setup will also look for mutations of the DOM and and matching elements will also be setup if they are injected into the DOM after initial setup.
3. CSS (optional)
You don't have to use the Shr CSS. You're free to style the buttons how you like. You can either include the SASS in your build or use the CDN hosted CSS in your <head>:
Ir you want to display the icons for each social network as per the demo, you can use the included SVG sprite. If you already have a sprite system, then you can include the SVG icons as-is. Otherwise, you can use something like sprite.js.
API
A few useful methods are exposed. To call an API method, you need a reference to the instance. This is returned from Shr.setup or your call the the constructor (new Shr), e.g.:
const button = new Shr('.js-shr-facebook', { ...options });
button
.getCount()
.then(count => {
// Do something with count 😎
})
.catch(error => {
// Something went wrong 😢
});
Method
Parameters
Description
getCount()
-
Returns a Promise that will either resolve with a count or an error.
openPopup(event)
Event
Open the associated dialog. This will be blocked unless it is as a result of user input. We'd suggest calling this as the callback for addEventListener or similar and passing the relevant event.
The following needs revision.
Options
There are a ton of options that ship with Shr. These allow you to customize the library to your needs.
debug
Default: falseType: Boolean
If you are are just debugging Shr in a development environment, you can turn on debugging when you setup.
Shr.setup('.js-shr', {
debug: true,
});
count.className
Default: shr__countType: String
When adding the share count element to the screen, this is the className used to style it.
Sometimes your URL has not been shared yet. You can choose whether or not you want to display 0 shares or not. Some APIs don't allow for the actual count, so those APIs will just be a link to share (such as Twitter) and won't show the count if this is turned on or not.
By default, Shr shortens the amount of shares to an easier to read number. Say you have a URL that went viral and you have over 1 million shares. By default, Shr shows this as 1 M. You can, however, turn this off and show the exact amount of shares.
By default, the number of shares shows up after the social icon. This means it's to the right of the icon. You can change this to be before the social icon (the left of the icon) by setting this value to before.
When the user clicks the share icon, we automatically update the count. However, this is assuming that the user went through with the sharing. This is for speed and reactivity. If you don't want this behavior, you can set this value to false.
{
enabled: Boolean, // Whether storage is supported
key: String, // Key to be used in local storage - (NOTE: can't contain special characters or whitespace)
ttl: Number, // Seconds to keep the storage valid
}
To save requests and speed up your site, Shr saves all of the values used to local storage. The two keys you can set are the key of the local storage and the time to live (AKA: how long do you want these values to last before we refresh). These can be customized to your liking in the setup like.
Shr provides a ton of networks that can be used on your site. Each button has certain attributes that need to be defined in order for Shr to operate efficiently and effictively. Below are descriptions and an example of each button and how to use it.
Twitter
This button allows you to tweet a URL on Twitter. A count is not available for this button due to Twitter deciding to remove the API endpoint, for whatever reason.
When entering your URL for Facebook, make sure it's properly URL encoded! The number of shares will appear next to the button for the URL you are sharing.
GitHub
This button allows you to star a repo on GitHub and shows the current number of stars for the project.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/sampotts/shr là nguồn chính thức.
sampotts/shr có bao nhiêu sao?
sampotts/shr có 150 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/sampotts/shr. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
sampotts/shr có phải mã nguồn mở không?
Có — sampotts/shr phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/sampotts/shr.
sampotts/shr còn đang phát triển không?
Commit gần nhất trên sampotts/shr là 3.6 năm trước (theo timestamp GitHub). Repo có 19 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
sampotts/shr dùng license gì?
sampotts/shr phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
sampotts/shr là gì?
sampotts/shr (sampotts/shr) là dự án JavaScript trên GitHub. Theo mô tả gốc: Simple, clean, and customizable social sharing buttons.
sampotts/shr viết bằng ngôn ngữ gì?
sampotts/shr chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc shr có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về shr.