-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
46 lines (35 loc) · 1.58 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {version} from './package';
import badgen from 'badgen';
import escape from 'escape-html';
document.querySelector('.version').innerText = `v${version}`;
const badgeLinkUrl = username => `https://tippin.me/@${username}`;
const badgeImageUrl = username => `https://badgen.net/badge/%E2%9A%A1%EF%B8%8Ftippin.me/@${username}/F0918E`;
const badgeSVG = username => badgen({
subject: '⚡️tippin.me',
status: `@${username}`,
color: 'F0918E',
});
const badgeHtmlPreview = username =>
`<a href="${badgeLinkUrl(username)}" rel="noopener noreferrer" target="_blank">
${badgeSVG(username)}
</a>`;
const badgeHtml = username =>
`<a href="${badgeLinkUrl(username)}" rel="noopener noreferrer" target="_blank">
<img src="${badgeImageUrl(username)}" alt="@${username} on tippin.me"/>
</a>`;
const badgeMarkdown = username =>
`[![tippin.me](${badgeImageUrl(username)})](${badgeLinkUrl(username)})`;
const usernameInput = document.querySelector('input[name="username"]');
const badgePreview = document.querySelector('.badge-preview');
const badgeHtmlSource = document.querySelector('.badge-html');
const badgeMarkdownSource = document.querySelector('.badge-markdown');
const badgeSvgSource = document.querySelector('.badge-svg');
const generateBadge = () => {
const username = escape(usernameInput.value) || 'username';
badgePreview.innerHTML = badgeHtmlPreview(username);
badgeHtmlSource.innerText = badgeHtml(username);
badgeMarkdownSource.innerText = badgeMarkdown(username);
badgeSvgSource.innerText = badgeSVG(username);
};
generateBadge();
usernameInput.addEventListener('input', generateBadge);