-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.html
153 lines (126 loc) · 4.8 KB
/
index.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
<title>Shields.io Patreon Badge Generator</title>
<meta charset="UTF-8">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet">
<style>
body.loading { cursor: progress; }
body {
font-family: 'Nunito', Arial, sans-serif;
text-align: center;
}
a { color: #000; font-weight: bold; }
a:hover { text-decoration: none; }
ul { list-style: none; }
ul li { display: inline-block; }
ul li label { margin-right: 1em; }
</style>
</head>
<body>
<h1>🛡 <a href="https://github.com/endel/shieldsio-patreon">Shields.io Patreon Badge Generator</a></h1>
<p>Custom endpoint to allow displaying Patreon's number of patrons or amount of pledges.</p>
<p></p>
<label for="username">Patreon Username:</label>
<input id="username" name="username" placeholder="username" value="endel" onchange="rebuild();" />
<br />
<ul>
<li>
<label for="type_pledges">
Show pledges $
<input id="type_pledges" name="type" type="radio" value="pledges" onchange="rebuild();">
</label>
<label for="type_patrons">
Show amount of patrons
<input id="type_patrons" name="type" type="radio" value="patrons" checked="checked" onchange="rebuild();">
</label>
</li>
</ul>
<ul>
<li>
<label for="style_plastic">
plastic
<input id="style_plastic" name="style" type="radio" value="plastic" onchange="rebuild();">
</label>
</li>
<li>
<label for="style_flat">
flat
<input id="style_flat" name="style" type="radio" value="flat" onchange="rebuild();" checked="checked">
</label>
</li>
<li>
<label for="style_flatsquare">
flat-square
<input id="style_flatsquare" name="style" type="radio" value="flat-square" onchange="rebuild();">
</label>
</li>
<li>
<label for="style_forthebadge">
for-the-badge
<input id="style_forthebadge" name="style" type="radio" value="for-the-badge" onchange="rebuild();">
</label>
</li>
<li>
<label for="style_social">
social
<input id="style_social" name="style" type="radio" value="social" onchange="rebuild();">
</label>
</li>
</ul>
<input name="suffix" placeholder="suffix (optional)" value="" onchange="rebuild();"/>
<div>
<h2>Preview</h2>
<img id="preview" src="" alt="Loading..." />
<br />
<h3>
Format →
<label for="format_markdown">
Markdown
<input id="format_markdown" type="radio" name="format" checked="checked" onchange="rebuild('markdown');">
</label>
<label for="format_html">
HTML
<input id="format_html" type="radio" name="format" onchange="rebuild('html');">
</label>
</h3>
<textarea id="markdown" cols="60" rows="6"></textarea>
<p><em>You may override some configurations for this badge. <br />Check out the <a href="https://shields.io/#/endpoint">shields.io's Endpoint feature</a> documentation.</em></p>
</div>
<script type="text/javascript">
var imageSrc, linkUrl, formatSelected = 'markdown';
function rebuild(format) {
if (format) { formatSelected = format; }
document.body.classList.add("loading");
var img = document.querySelector('img#preview');
img.src = "https://img.shields.io/badge/%20loading-brightgreen.svg?style=for-the-badge&colorB=000000";
var username = document.querySelector('input[name=username]').value;
var type = document.querySelector('input[type=radio][name=type]:checked').value;
var style = document.querySelector('input[type=radio][name=style]:checked').value;
var suffix = document.querySelector('input[name=suffix]').value;
var endpointUrl = `https://shieldsio-patreon.vercel.app/api?username=${username}&type=${type}`;
if (suffix) { endpointUrl += `&suffix=${encodeURIComponent(suffix)}`; }
imageSrc = `https://img.shields.io/endpoint.svg?url=${encodeURIComponent(endpointUrl)}&style=${style}`;
linkUrl = `https://patreon.com/${username}`;
img.src = imageSrc;
img.onload = function() { document.body.classList.remove("loading"); }
writeFormat(formatSelected);
}
function writeFormat(format) {
var textarea = document.querySelector('textarea#markdown');
if (format === "markdown") {
// markdown format
textarea.innerHTML = `[![Support me on Patreon](${imageSrc})](${linkUrl})`;
} else {
// html format
textarea.innerHTML = `<a href="${linkUrl}"><img src="${imageSrc}" alt="Support me on Patreon" /></a>`;
}
}
rebuild();
</script>
<footer>
Made with ❤️ by <a href="https://www.patreon.com/endel">Endel</a>
</footer>
</body>
</html>