tinyshare 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.js +615 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# tinyshare
|
|
2
|
+
|
|
3
|
+
tinyshare is a tiny TypeScript-first helper for building social sharing URLs and opening share windows. It's a small, typed fork of the popular [Sharer.js](https://github.com/ellisonleao/sharer.js) project by Ellison Leao.
|
|
4
|
+
|
|
5
|
+
## Why `tinyshare`?
|
|
6
|
+
|
|
7
|
+
- TypeScript-first: sharer options are typed per-service so incorrect options are caught at compile time.
|
|
8
|
+
- Tiny: single-file module with no runtime dependencies.
|
|
9
|
+
- Can be used with any UI library (e.g. Vue, React, or plain vanilla JS) because it only handles the sharing part (as opposed to Sharer.js which also bind to HTML elements)
|
|
10
|
+
- Compatible: preserves the original sharing logic and URL formats from Sharer.js.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import share from 'tinyshare'
|
|
16
|
+
|
|
17
|
+
// share(url, sharerName, options)
|
|
18
|
+
share('https://example.com', 'twitter', { title: 'Hello', hashtags: 'news' })
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Publishing
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
np
|
|
25
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @preserve
|
|
3
|
+
* Sharer.js
|
|
4
|
+
*
|
|
5
|
+
* @description Create your own social share buttons
|
|
6
|
+
* @version 0.5.1
|
|
7
|
+
* @author Ellison Leao <ellisonleao@gmail.com>
|
|
8
|
+
* @license MIT
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export type SharerName = 'facebook' | 'linkedin' | 'twitter' | 'x' | 'threads' | 'bluesky' | 'email' | 'whatsapp' | 'telegram' | 'viber' | 'line' | 'pinterest' | 'tumblr' | 'hackernews' | 'reddit' | 'vk' | 'xing' | 'buffer' | 'instapaper' | 'pocket' | 'mashable' | 'mix' | 'flipboard' | 'weibo' | 'blogger' | 'baidu' | 'douban' | 'okru' | 'mailru' | 'evernote' | 'skype' | 'delicious' | 'sms' | 'trello' | 'messenger' | 'odnoklassniki' | 'meneame' | 'diaspora' | 'googlebookmarks' | 'qzone' | 'refind' | 'surfingbird' | 'yahoomail' | 'wordpress' | 'amazon' | 'pinboard' | 'threema' | 'kakaostory' | 'yummly';
|
|
12
|
+
interface PopupOptions {
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
}
|
|
16
|
+
interface BaseShareOptions {
|
|
17
|
+
onWindowClose?: () => void;
|
|
18
|
+
title?: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
link?: boolean;
|
|
21
|
+
blank?: boolean;
|
|
22
|
+
popup?: PopupOptions;
|
|
23
|
+
}
|
|
24
|
+
interface ShareOptionsBySharer {
|
|
25
|
+
facebook: BaseShareOptions & {
|
|
26
|
+
hashtag?: string;
|
|
27
|
+
quote?: string;
|
|
28
|
+
};
|
|
29
|
+
linkedin: BaseShareOptions;
|
|
30
|
+
twitter: BaseShareOptions & {
|
|
31
|
+
hashtags?: string;
|
|
32
|
+
via?: string;
|
|
33
|
+
related?: string;
|
|
34
|
+
in_reply_to?: string;
|
|
35
|
+
};
|
|
36
|
+
x: BaseShareOptions & {
|
|
37
|
+
hashtags?: string;
|
|
38
|
+
via?: string;
|
|
39
|
+
related?: string;
|
|
40
|
+
in_reply_to?: string;
|
|
41
|
+
};
|
|
42
|
+
threads: BaseShareOptions;
|
|
43
|
+
bluesky: BaseShareOptions;
|
|
44
|
+
email: BaseShareOptions & {
|
|
45
|
+
to?: string;
|
|
46
|
+
subject?: string;
|
|
47
|
+
};
|
|
48
|
+
whatsapp: BaseShareOptions & {
|
|
49
|
+
web?: boolean;
|
|
50
|
+
to?: string;
|
|
51
|
+
};
|
|
52
|
+
telegram: BaseShareOptions;
|
|
53
|
+
viber: BaseShareOptions;
|
|
54
|
+
line: BaseShareOptions;
|
|
55
|
+
pinterest: BaseShareOptions & {
|
|
56
|
+
image?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
};
|
|
59
|
+
tumblr: BaseShareOptions & {
|
|
60
|
+
caption?: string;
|
|
61
|
+
tags?: string;
|
|
62
|
+
};
|
|
63
|
+
hackernews: BaseShareOptions;
|
|
64
|
+
reddit: BaseShareOptions;
|
|
65
|
+
vk: BaseShareOptions & {
|
|
66
|
+
caption?: string;
|
|
67
|
+
image?: string;
|
|
68
|
+
};
|
|
69
|
+
xing: BaseShareOptions;
|
|
70
|
+
buffer: BaseShareOptions & {
|
|
71
|
+
via?: string;
|
|
72
|
+
picture?: string;
|
|
73
|
+
};
|
|
74
|
+
instapaper: BaseShareOptions & {
|
|
75
|
+
description?: string;
|
|
76
|
+
};
|
|
77
|
+
pocket: BaseShareOptions;
|
|
78
|
+
mashable: BaseShareOptions;
|
|
79
|
+
mix: BaseShareOptions;
|
|
80
|
+
flipboard: BaseShareOptions;
|
|
81
|
+
weibo: BaseShareOptions & {
|
|
82
|
+
image?: string;
|
|
83
|
+
appkey?: string;
|
|
84
|
+
ralateuid?: string;
|
|
85
|
+
};
|
|
86
|
+
blogger: BaseShareOptions & {
|
|
87
|
+
description?: string;
|
|
88
|
+
};
|
|
89
|
+
baidu: BaseShareOptions;
|
|
90
|
+
douban: BaseShareOptions & {
|
|
91
|
+
name?: string;
|
|
92
|
+
image?: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
};
|
|
95
|
+
okru: BaseShareOptions;
|
|
96
|
+
mailru: BaseShareOptions & {
|
|
97
|
+
description?: string;
|
|
98
|
+
};
|
|
99
|
+
evernote: BaseShareOptions;
|
|
100
|
+
skype: BaseShareOptions;
|
|
101
|
+
delicious: BaseShareOptions;
|
|
102
|
+
sms: BaseShareOptions & {
|
|
103
|
+
body?: string;
|
|
104
|
+
};
|
|
105
|
+
trello: BaseShareOptions & {
|
|
106
|
+
description?: string;
|
|
107
|
+
};
|
|
108
|
+
messenger: BaseShareOptions;
|
|
109
|
+
odnoklassniki: BaseShareOptions;
|
|
110
|
+
meneame: BaseShareOptions;
|
|
111
|
+
diaspora: BaseShareOptions;
|
|
112
|
+
googlebookmarks: BaseShareOptions;
|
|
113
|
+
qzone: BaseShareOptions;
|
|
114
|
+
refind: BaseShareOptions;
|
|
115
|
+
surfingbird: BaseShareOptions & {
|
|
116
|
+
description?: string;
|
|
117
|
+
};
|
|
118
|
+
yahoomail: BaseShareOptions & {
|
|
119
|
+
to?: string;
|
|
120
|
+
subject?: string;
|
|
121
|
+
body?: string;
|
|
122
|
+
};
|
|
123
|
+
wordpress: BaseShareOptions;
|
|
124
|
+
amazon: BaseShareOptions;
|
|
125
|
+
pinboard: BaseShareOptions & {
|
|
126
|
+
description?: string;
|
|
127
|
+
};
|
|
128
|
+
threema: BaseShareOptions & {
|
|
129
|
+
text?: string;
|
|
130
|
+
id?: string;
|
|
131
|
+
};
|
|
132
|
+
kakaostory: BaseShareOptions;
|
|
133
|
+
yummly: BaseShareOptions;
|
|
134
|
+
}
|
|
135
|
+
type ShareOptionsFor<S extends SharerName> = ShareOptionsBySharer[S];
|
|
136
|
+
export declare const share: <S extends SharerName>(url: string, sharer: S, options: Omit<ShareOptionsFor<S>, "url">) => string | false;
|
|
137
|
+
export default share;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @preserve
|
|
3
|
+
* Sharer.js
|
|
4
|
+
*
|
|
5
|
+
* @description Create your own social share buttons
|
|
6
|
+
* @version 0.5.1
|
|
7
|
+
* @author Ellison Leao <ellisonleao@gmail.com>
|
|
8
|
+
* @license MIT
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
;
|
|
12
|
+
const normalizeHashtag = (value) => {
|
|
13
|
+
if (!value) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (value.startsWith('#')) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
return `#${value}`;
|
|
20
|
+
};
|
|
21
|
+
const sharerBuilders = {
|
|
22
|
+
facebook: (options) => {
|
|
23
|
+
const url = options.url ?? '';
|
|
24
|
+
return {
|
|
25
|
+
shareUrl: 'https://www.facebook.com/sharer/sharer.php',
|
|
26
|
+
params: {
|
|
27
|
+
u: url,
|
|
28
|
+
hashtag: normalizeHashtag(options.hashtag),
|
|
29
|
+
quote: options.quote,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
linkedin: (options) => {
|
|
34
|
+
const url = options.url ?? '';
|
|
35
|
+
return {
|
|
36
|
+
shareUrl: 'https://www.linkedin.com/shareArticle',
|
|
37
|
+
params: {
|
|
38
|
+
url,
|
|
39
|
+
mini: true,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
twitter: (options) => {
|
|
44
|
+
const title = options.title ?? '';
|
|
45
|
+
const url = options.url ?? '';
|
|
46
|
+
return {
|
|
47
|
+
shareUrl: 'https://twitter.com/intent/tweet',
|
|
48
|
+
params: {
|
|
49
|
+
text: title,
|
|
50
|
+
url,
|
|
51
|
+
hashtags: options.hashtags,
|
|
52
|
+
via: options.via,
|
|
53
|
+
related: options.related,
|
|
54
|
+
in_reply_to: options.in_reply_to,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
x: (options) => {
|
|
59
|
+
const title = options.title ?? '';
|
|
60
|
+
const url = options.url ?? '';
|
|
61
|
+
return {
|
|
62
|
+
shareUrl: 'https://x.com/intent/tweet',
|
|
63
|
+
params: {
|
|
64
|
+
text: title,
|
|
65
|
+
url,
|
|
66
|
+
hashtags: options.hashtags,
|
|
67
|
+
via: options.via,
|
|
68
|
+
related: options.related,
|
|
69
|
+
in_reply_to: options.in_reply_to,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
threads: (options) => {
|
|
74
|
+
const title = options.title ?? '';
|
|
75
|
+
const url = options.url ?? '';
|
|
76
|
+
return {
|
|
77
|
+
shareUrl: 'https://threads.net/intent/post',
|
|
78
|
+
params: {
|
|
79
|
+
text: `${title} ${url}`.trim(),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
bluesky: (options) => {
|
|
84
|
+
const title = options.title ?? '';
|
|
85
|
+
const url = options.url ?? '';
|
|
86
|
+
return {
|
|
87
|
+
shareUrl: 'https://bsky.app/intent/compose',
|
|
88
|
+
params: {
|
|
89
|
+
text: `${title} ${url}`.trim(),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
email: (options) => {
|
|
94
|
+
const title = options.title ?? '';
|
|
95
|
+
const url = options.url ?? '';
|
|
96
|
+
return {
|
|
97
|
+
shareUrl: `mailto:${options.to ?? ''}`,
|
|
98
|
+
params: {
|
|
99
|
+
subject: options.subject,
|
|
100
|
+
body: `${title}\n${url}`.trim(),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
whatsapp: (options) => {
|
|
105
|
+
const title = options.title ?? '';
|
|
106
|
+
const url = options.url ?? '';
|
|
107
|
+
return {
|
|
108
|
+
shareUrl: options.web ? 'https://web.whatsapp.com/send' : 'https://wa.me/',
|
|
109
|
+
params: {
|
|
110
|
+
phone: options.to,
|
|
111
|
+
text: `${title} ${url}`.trim(),
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
telegram: (options) => {
|
|
116
|
+
const title = options.title ?? '';
|
|
117
|
+
const url = options.url ?? '';
|
|
118
|
+
return {
|
|
119
|
+
shareUrl: 'https://t.me/share',
|
|
120
|
+
params: {
|
|
121
|
+
text: title,
|
|
122
|
+
url,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
viber: (options) => {
|
|
127
|
+
const title = options.title ?? '';
|
|
128
|
+
const url = options.url ?? '';
|
|
129
|
+
return {
|
|
130
|
+
shareUrl: 'viber://forward',
|
|
131
|
+
params: {
|
|
132
|
+
text: `${title} ${url}`.trim(),
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
line: (options) => {
|
|
137
|
+
const title = options.title ?? '';
|
|
138
|
+
const url = options.url ?? '';
|
|
139
|
+
return {
|
|
140
|
+
shareUrl: `http://line.me/R/msg/text/?${encodeURIComponent(`${title} ${url}`.trim())}`,
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
pinterest: (options) => {
|
|
144
|
+
const url = options.url ?? '';
|
|
145
|
+
return {
|
|
146
|
+
shareUrl: 'https://www.pinterest.com/pin/create/button/',
|
|
147
|
+
params: {
|
|
148
|
+
url,
|
|
149
|
+
media: options.image,
|
|
150
|
+
description: options.description,
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
tumblr: (options) => {
|
|
155
|
+
const title = options.title ?? '';
|
|
156
|
+
const url = options.url ?? '';
|
|
157
|
+
return {
|
|
158
|
+
shareUrl: 'http://tumblr.com/widgets/share/tool',
|
|
159
|
+
params: {
|
|
160
|
+
canonicalUrl: url,
|
|
161
|
+
content: url,
|
|
162
|
+
posttype: 'link',
|
|
163
|
+
title,
|
|
164
|
+
caption: options.caption,
|
|
165
|
+
tags: options.tags,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
hackernews: (options) => {
|
|
170
|
+
const title = options.title ?? '';
|
|
171
|
+
const url = options.url ?? '';
|
|
172
|
+
return {
|
|
173
|
+
shareUrl: 'https://news.ycombinator.com/submitlink',
|
|
174
|
+
params: {
|
|
175
|
+
u: url,
|
|
176
|
+
t: title,
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
reddit: (options) => {
|
|
181
|
+
const title = options.title ?? '';
|
|
182
|
+
const url = options.url ?? '';
|
|
183
|
+
return {
|
|
184
|
+
shareUrl: 'https://www.reddit.com/submit',
|
|
185
|
+
params: {
|
|
186
|
+
url,
|
|
187
|
+
title,
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
vk: (options) => {
|
|
192
|
+
const title = options.title ?? '';
|
|
193
|
+
const url = options.url ?? '';
|
|
194
|
+
return {
|
|
195
|
+
shareUrl: 'http://vk.com/share.php',
|
|
196
|
+
params: {
|
|
197
|
+
url,
|
|
198
|
+
title,
|
|
199
|
+
description: options.caption,
|
|
200
|
+
image: options.image,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
xing: (options) => {
|
|
205
|
+
const url = options.url ?? '';
|
|
206
|
+
return {
|
|
207
|
+
shareUrl: 'https://www.xing.com/social/share/spi',
|
|
208
|
+
params: {
|
|
209
|
+
url,
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
buffer: (options) => {
|
|
214
|
+
const title = options.title ?? '';
|
|
215
|
+
const url = options.url ?? '';
|
|
216
|
+
return {
|
|
217
|
+
shareUrl: 'https://buffer.com/add',
|
|
218
|
+
params: {
|
|
219
|
+
url,
|
|
220
|
+
title,
|
|
221
|
+
via: options.via,
|
|
222
|
+
picture: options.picture,
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
instapaper: (options) => {
|
|
227
|
+
const title = options.title ?? '';
|
|
228
|
+
const url = options.url ?? '';
|
|
229
|
+
return {
|
|
230
|
+
shareUrl: 'http://www.instapaper.com/edit',
|
|
231
|
+
params: {
|
|
232
|
+
url,
|
|
233
|
+
title,
|
|
234
|
+
description: options.description,
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
},
|
|
238
|
+
pocket: (options) => {
|
|
239
|
+
const url = options.url ?? '';
|
|
240
|
+
return {
|
|
241
|
+
shareUrl: 'https://getpocket.com/save',
|
|
242
|
+
params: {
|
|
243
|
+
url,
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
mashable: (options) => {
|
|
248
|
+
const title = options.title ?? '';
|
|
249
|
+
const url = options.url ?? '';
|
|
250
|
+
return {
|
|
251
|
+
shareUrl: 'https://mashable.com/submit',
|
|
252
|
+
params: {
|
|
253
|
+
url,
|
|
254
|
+
title,
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
},
|
|
258
|
+
mix: (options) => {
|
|
259
|
+
const url = options.url ?? '';
|
|
260
|
+
return {
|
|
261
|
+
shareUrl: 'https://mix.com/add',
|
|
262
|
+
params: {
|
|
263
|
+
url,
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
flipboard: (options) => {
|
|
268
|
+
const title = options.title ?? '';
|
|
269
|
+
const url = options.url ?? '';
|
|
270
|
+
return {
|
|
271
|
+
shareUrl: 'https://share.flipboard.com/bookmarklet/popout',
|
|
272
|
+
params: {
|
|
273
|
+
v: 2,
|
|
274
|
+
title,
|
|
275
|
+
url,
|
|
276
|
+
t: Date.now(),
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
weibo: (options) => {
|
|
281
|
+
const title = options.title ?? '';
|
|
282
|
+
const url = options.url ?? '';
|
|
283
|
+
return {
|
|
284
|
+
shareUrl: 'http://service.weibo.com/share/share.php',
|
|
285
|
+
params: {
|
|
286
|
+
url,
|
|
287
|
+
title,
|
|
288
|
+
pic: options.image,
|
|
289
|
+
appkey: options.appkey,
|
|
290
|
+
ralateUid: options.ralateuid,
|
|
291
|
+
language: 'zh_cn',
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
},
|
|
295
|
+
blogger: (options) => {
|
|
296
|
+
const title = options.title ?? '';
|
|
297
|
+
const url = options.url ?? '';
|
|
298
|
+
return {
|
|
299
|
+
shareUrl: 'https://www.blogger.com/blog-this.g',
|
|
300
|
+
params: {
|
|
301
|
+
u: url,
|
|
302
|
+
n: title,
|
|
303
|
+
t: options.description,
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
baidu: (options) => {
|
|
308
|
+
const title = options.title ?? '';
|
|
309
|
+
const url = options.url ?? '';
|
|
310
|
+
return {
|
|
311
|
+
shareUrl: 'http://cang.baidu.com/do/add',
|
|
312
|
+
params: {
|
|
313
|
+
it: title,
|
|
314
|
+
iu: url,
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
},
|
|
318
|
+
douban: (options) => {
|
|
319
|
+
const url = options.url ?? '';
|
|
320
|
+
return {
|
|
321
|
+
shareUrl: 'https://www.douban.com/share/service',
|
|
322
|
+
params: {
|
|
323
|
+
name: options.name,
|
|
324
|
+
href: url,
|
|
325
|
+
image: options.image,
|
|
326
|
+
comment: options.description,
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
okru: (options) => {
|
|
331
|
+
const title = options.title ?? '';
|
|
332
|
+
const url = options.url ?? '';
|
|
333
|
+
return {
|
|
334
|
+
shareUrl: 'https://connect.ok.ru/dk',
|
|
335
|
+
params: {
|
|
336
|
+
'st.cmd': 'WidgetSharePreview',
|
|
337
|
+
'st.shareUrl': url,
|
|
338
|
+
title,
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
mailru: (options) => {
|
|
343
|
+
const title = options.title ?? '';
|
|
344
|
+
const url = options.url ?? '';
|
|
345
|
+
return {
|
|
346
|
+
shareUrl: 'http://connect.mail.ru/share',
|
|
347
|
+
params: {
|
|
348
|
+
share_url: url,
|
|
349
|
+
linkname: title,
|
|
350
|
+
linknote: options.description,
|
|
351
|
+
type: 'page',
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
},
|
|
355
|
+
evernote: (options) => {
|
|
356
|
+
const title = options.title ?? '';
|
|
357
|
+
const url = options.url ?? '';
|
|
358
|
+
return {
|
|
359
|
+
shareUrl: 'https://www.evernote.com/clip.action',
|
|
360
|
+
params: {
|
|
361
|
+
url,
|
|
362
|
+
title,
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
skype: (options) => {
|
|
367
|
+
const title = options.title ?? '';
|
|
368
|
+
const url = options.url ?? '';
|
|
369
|
+
return {
|
|
370
|
+
shareUrl: 'https://web.skype.com/share',
|
|
371
|
+
params: {
|
|
372
|
+
url,
|
|
373
|
+
title,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
},
|
|
377
|
+
delicious: (options) => {
|
|
378
|
+
const title = options.title ?? '';
|
|
379
|
+
const url = options.url ?? '';
|
|
380
|
+
return {
|
|
381
|
+
shareUrl: 'https://del.icio.us/post',
|
|
382
|
+
params: {
|
|
383
|
+
url,
|
|
384
|
+
title,
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
},
|
|
388
|
+
sms: (options) => ({
|
|
389
|
+
shareUrl: 'sms://',
|
|
390
|
+
params: {
|
|
391
|
+
body: options.body,
|
|
392
|
+
},
|
|
393
|
+
}),
|
|
394
|
+
trello: (options) => {
|
|
395
|
+
const title = options.title ?? '';
|
|
396
|
+
const url = options.url ?? '';
|
|
397
|
+
return {
|
|
398
|
+
shareUrl: 'https://trello.com/add-card',
|
|
399
|
+
params: {
|
|
400
|
+
url,
|
|
401
|
+
name: title,
|
|
402
|
+
desc: options.description,
|
|
403
|
+
mode: 'popup',
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
},
|
|
407
|
+
messenger: (options) => {
|
|
408
|
+
const url = options.url ?? '';
|
|
409
|
+
return {
|
|
410
|
+
shareUrl: 'fb-messenger://share',
|
|
411
|
+
params: {
|
|
412
|
+
link: url,
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
},
|
|
416
|
+
odnoklassniki: (options) => {
|
|
417
|
+
const url = options.url ?? '';
|
|
418
|
+
return {
|
|
419
|
+
shareUrl: 'https://connect.ok.ru/dk',
|
|
420
|
+
params: {
|
|
421
|
+
'st.cmd': 'WidgetSharePreview',
|
|
422
|
+
'st.deprecated': 1,
|
|
423
|
+
'st.shareUrl': url,
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
},
|
|
427
|
+
meneame: (options) => {
|
|
428
|
+
const url = options.url ?? '';
|
|
429
|
+
return {
|
|
430
|
+
shareUrl: 'https://www.meneame.net/submit',
|
|
431
|
+
params: {
|
|
432
|
+
url,
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
},
|
|
436
|
+
diaspora: (options) => {
|
|
437
|
+
const title = options.title ?? '';
|
|
438
|
+
const url = options.url ?? '';
|
|
439
|
+
return {
|
|
440
|
+
shareUrl: 'https://share.diasporafoundation.org',
|
|
441
|
+
params: {
|
|
442
|
+
title,
|
|
443
|
+
url,
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
},
|
|
447
|
+
googlebookmarks: (options) => {
|
|
448
|
+
const title = options.title ?? '';
|
|
449
|
+
const url = options.url ?? '';
|
|
450
|
+
return {
|
|
451
|
+
shareUrl: 'https://www.google.com/bookmarks/mark',
|
|
452
|
+
params: {
|
|
453
|
+
op: 'edit',
|
|
454
|
+
bkmk: url,
|
|
455
|
+
title,
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
},
|
|
459
|
+
qzone: (options) => {
|
|
460
|
+
const url = options.url ?? '';
|
|
461
|
+
return {
|
|
462
|
+
shareUrl: 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey',
|
|
463
|
+
params: {
|
|
464
|
+
url,
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
},
|
|
468
|
+
refind: (options) => {
|
|
469
|
+
const url = options.url ?? '';
|
|
470
|
+
return {
|
|
471
|
+
shareUrl: 'https://refind.com',
|
|
472
|
+
params: {
|
|
473
|
+
url,
|
|
474
|
+
},
|
|
475
|
+
};
|
|
476
|
+
},
|
|
477
|
+
surfingbird: (options) => {
|
|
478
|
+
const title = options.title ?? '';
|
|
479
|
+
const url = options.url ?? '';
|
|
480
|
+
return {
|
|
481
|
+
shareUrl: 'https://surfingbird.ru/share',
|
|
482
|
+
params: {
|
|
483
|
+
url,
|
|
484
|
+
title,
|
|
485
|
+
description: options.description,
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
yahoomail: (options) => ({
|
|
490
|
+
shareUrl: 'http://compose.mail.yahoo.com',
|
|
491
|
+
params: {
|
|
492
|
+
to: options.to,
|
|
493
|
+
subject: options.subject,
|
|
494
|
+
body: options.body,
|
|
495
|
+
},
|
|
496
|
+
}),
|
|
497
|
+
wordpress: (options) => {
|
|
498
|
+
const title = options.title ?? '';
|
|
499
|
+
const url = options.url ?? '';
|
|
500
|
+
return {
|
|
501
|
+
shareUrl: 'https://wordpress.com/wp-admin/press-this.php',
|
|
502
|
+
params: {
|
|
503
|
+
u: url,
|
|
504
|
+
t: title,
|
|
505
|
+
s: title,
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
},
|
|
509
|
+
amazon: (options) => {
|
|
510
|
+
const title = options.title ?? '';
|
|
511
|
+
const url = options.url ?? '';
|
|
512
|
+
return {
|
|
513
|
+
shareUrl: 'https://www.amazon.com/gp/wishlist/static-add',
|
|
514
|
+
params: {
|
|
515
|
+
u: url,
|
|
516
|
+
t: title,
|
|
517
|
+
},
|
|
518
|
+
};
|
|
519
|
+
},
|
|
520
|
+
pinboard: (options) => {
|
|
521
|
+
const title = options.title ?? '';
|
|
522
|
+
const url = options.url ?? '';
|
|
523
|
+
return {
|
|
524
|
+
shareUrl: 'https://pinboard.in/add',
|
|
525
|
+
params: {
|
|
526
|
+
url,
|
|
527
|
+
title,
|
|
528
|
+
description: options.description,
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
},
|
|
532
|
+
threema: (options) => ({
|
|
533
|
+
shareUrl: 'threema://compose',
|
|
534
|
+
params: {
|
|
535
|
+
text: options.text,
|
|
536
|
+
id: options.id,
|
|
537
|
+
},
|
|
538
|
+
}),
|
|
539
|
+
kakaostory: (options) => {
|
|
540
|
+
const url = options.url ?? '';
|
|
541
|
+
return {
|
|
542
|
+
shareUrl: 'https://story.kakao.com/share',
|
|
543
|
+
params: {
|
|
544
|
+
url,
|
|
545
|
+
},
|
|
546
|
+
};
|
|
547
|
+
},
|
|
548
|
+
yummly: (options) => {
|
|
549
|
+
const title = options.title ?? '';
|
|
550
|
+
const url = options.url ?? '';
|
|
551
|
+
return {
|
|
552
|
+
shareUrl: 'http://www.yummly.com/urb/verify',
|
|
553
|
+
params: {
|
|
554
|
+
url,
|
|
555
|
+
title,
|
|
556
|
+
yumtype: 'button',
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
const buildSharerConfig = (sharer, options) => {
|
|
562
|
+
const config = sharerBuilders[sharer](options);
|
|
563
|
+
if (options.popup?.width) {
|
|
564
|
+
config.width = options.popup.width;
|
|
565
|
+
}
|
|
566
|
+
if (options.popup?.height) {
|
|
567
|
+
config.height = options.popup.height;
|
|
568
|
+
}
|
|
569
|
+
return config;
|
|
570
|
+
};
|
|
571
|
+
const buildShareUrl = (config) => {
|
|
572
|
+
const params = config.params ?? {};
|
|
573
|
+
const keys = Object.keys(params);
|
|
574
|
+
if (keys.length === 0) {
|
|
575
|
+
return config.shareUrl;
|
|
576
|
+
}
|
|
577
|
+
const query = keys
|
|
578
|
+
.filter((key) => params[key] !== undefined && params[key] !== '')
|
|
579
|
+
.map((key) => `${key}=${encodeURIComponent(String(params[key]))}`)
|
|
580
|
+
.join('&');
|
|
581
|
+
return query ? `${config.shareUrl}?${query}` : config.shareUrl;
|
|
582
|
+
};
|
|
583
|
+
const openPopup = (shareUrl, width = 600, height = 480) => {
|
|
584
|
+
const left = window.innerWidth / 2 - width / 2 + window.screenX;
|
|
585
|
+
const top = window.innerHeight / 2 - height / 2 + window.screenY;
|
|
586
|
+
const popParams = `scrollbars=no, width=${width}, height=${height}, top=${top}, left=${left}`;
|
|
587
|
+
const newWindow = window.open(shareUrl, '', popParams);
|
|
588
|
+
newWindow?.focus();
|
|
589
|
+
return newWindow;
|
|
590
|
+
};
|
|
591
|
+
export const share = (url, sharer, options) => {
|
|
592
|
+
const merged = {
|
|
593
|
+
...options,
|
|
594
|
+
url,
|
|
595
|
+
};
|
|
596
|
+
const config = buildSharerConfig(sharer, merged);
|
|
597
|
+
if (!config) {
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
const shareUrl = buildShareUrl(config);
|
|
601
|
+
if (options.link) {
|
|
602
|
+
if (options.blank) {
|
|
603
|
+
const win = window.open(shareUrl, '_blank');
|
|
604
|
+
if (options.onWindowClose)
|
|
605
|
+
win?.addEventListener('close', options.onWindowClose, { once: true });
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
window.location.href = shareUrl;
|
|
609
|
+
}
|
|
610
|
+
return shareUrl;
|
|
611
|
+
}
|
|
612
|
+
openPopup(shareUrl, config.width ?? 600, config.height ?? 480);
|
|
613
|
+
return shareUrl;
|
|
614
|
+
};
|
|
615
|
+
export default share;
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tinyshare",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A tiny, TypeScript-first social share helper (fork of sharer.js)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"test": "yarn build",
|
|
18
|
+
"prepare": "yarn build"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"keywords": [
|
|
25
|
+
"share",
|
|
26
|
+
"social",
|
|
27
|
+
"sharer",
|
|
28
|
+
"typescript",
|
|
29
|
+
"tinyshare"
|
|
30
|
+
],
|
|
31
|
+
"author": {
|
|
32
|
+
"name": "Mikael Finstad",
|
|
33
|
+
"email": "finstaden@gmail.com"
|
|
34
|
+
},
|
|
35
|
+
"contributors": [
|
|
36
|
+
{
|
|
37
|
+
"name": "Ellison Leao",
|
|
38
|
+
"email": "ellisonleao@gmail.com"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/mifi/tinyshare.git"
|
|
45
|
+
},
|
|
46
|
+
"packageManager": "yarn@4.12.0",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@tsconfig/strictest": "^2.0.8",
|
|
49
|
+
"typescript": "^5.9.3"
|
|
50
|
+
}
|
|
51
|
+
}
|