-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.html
242 lines (203 loc) · 7.27 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<title><github-card>: A web component to show a profile-card for your Github account.</title>
<link rel="stylesheet" href="src/normalize.css">
<link rel="stylesheet" href="src/styles.css">
</head>
<body>
<header>
<h1><github-card></h1>
<h2>A web component to show a profile-card for your Github account.</h2>
</header>
<output id="cards">
<figure>
<img src="src/assets/example.png" width="267" height="302">
</figure>
</output>
<form id="create-card">
<input id="username" type="text" placeholder="Enter a Github username">
<button>Show</button>
</form>
<footer>
<iframe id="twitter" allowtransparency="true" frameborder="0" width="100" height="22" scrolling="no" src="https://platform.twitter.com/widgets/tweet_button.html?text=<github-card>%3A%20A%20Web%20Component%20to%20show%20a%20profile-card%20for%20your%20Github%20account.&url=http%3A%2F%2Fpazguille.github.io%2Fgithub-card"></iframe>
<a href="https://github.com/pazguille/github-card" id="github-ribbon"><img width="149" height="149" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
by <a href="http://pazguille.me/">Guille Paz</a> with <a href="http://welovefrontend.org/" class="heart">❤</a>
<iframe id="github-button" src="http://ghbtns.com/github-btn.html?user=pazguille&repo=github-card&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="152" height="30"></iframe>
</footer>
<template id="github-template">
<style>
:host {
display: inline-block;
}
.user {
font-family: "Helvetica", Arial, sans-serif;
display: inline-block;
width: 265px;
height: 300px;
overflow: hidden;
border-radius: 6px;
position: relative;
background-color: #2E353C;
text-align: center;
color: #fff;
font-weight: 100;
transition: background 1000ms ease-out;
}
.user dl,
.user dd {
margin: 0;
}
.user dt {
display: none;
}
.user-data {
background: #fff url('src/assets/github.png') no-repeat 5px 5px;
background-size: 25px;
height: 85px;
border: 1px solid #D5D5D5;
border-bottom:0;
}
dd.user-avatar {
display: inline-block;
margin: 20px 0 10px;
}
.user-avatar img {
border-radius: 100%;
height: 120px;
width: 120px;
border: 3px solid #fff;
vertical-align: middle;
background-color: #fff;
}
dd.user-name,
dd.user-account {
margin: 5px 0;
}
.user-name {
font-size: 24px;
}
.user-account {
font-size: 16px;
color: #999;
margin: 5px 0;
}
.user-stats {
border-top: 1px groove #999;
position: relative;
top: 155px;
}
.user-stats dd {
padding: 10px 20px;
}
.user-repos,
.user-following,
.user-followers {
display: inline-block;
font-size: 22px;
color: #999;
}
.user-repos:after,
.user-following:after,
.user-followers:after {
content: attr(data-stats);
text-transform: uppercase;
display: block;
font-size: 11px;
color: #666;
font-weight: normal;
line-height: 1.7em;
}
.spinner {
background: url('src/assets/spinner.gif') no-repeat center center;
}
a.user-github-url,
a.user-repos-url,
a.user-followers-url {
text-decoration: none;
}
</style>
<article class="user spinner">
<dl class="user-data" hidden>
<dt>Avatar:</dt>
<dd class="user-avatar">
<img src="">
</dd>
<dt>Fullname:</dt>
<dd class="user-name"></dd>
<dt>Account:</dt>
<a class="user-github-url"><dd class="user-account"></dd></a>
</dl>
<dl class="user-stats" hidden>
<dt>Repos</dt>
<a class="user-repos-url"><dd class="user-repos" data-stats="repos"></dd></a>
<dt>Followers</dt>
<a class="user-followers-url"><dd class="user-followers" data-stats="followers"></dd></a>
</dl>
</article>
</template>
<script>
class Xgithub extends HTMLElement {
constructor () {
super();
const template = document.querySelector('#github-template');
const usr = template.content.cloneNode(true);
this.attachShadow({ mode: 'open' });
this.shadowRoot.appendChild(usr);
}
async getUser() {
const user = await fetch(`https://api.github.com/users/${this.getAttribute('user')}`, {
headers: {
Authorization: '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',
}
}).then(res => res.json());
this.fillUser(user);
}
fillUser(user) {
const usr = this.shadowRoot;
usr.querySelector('.user-account').textContent = this.getAttribute('user');
usr.querySelector('.user-name').textContent = user.name;
usr.querySelector('.user-avatar img').src = user.avatar_url;
usr.querySelector('.user-repos').textContent = user.public_repos;
usr.querySelector('.user-followers').textContent = user.followers;
usr.querySelector('.user').classList.remove('spinner');
usr.querySelector('.user-data').removeAttribute('hidden');
usr.querySelector('.user-stats').removeAttribute('hidden');
usr.querySelector('.user-github-url').href = user.html_url;
usr.querySelector('.user-repos-url').href = user.html_url.concat('?tab=repositories');
usr.querySelector('.user-followers-url').href = user.html_url.concat('?tab=followers');
}
connectedCallback() {
this.getUser();
}
attributeChangedCallback() {
this.getUser();
}
}
if (!window.customElements.get('github-card')) {
window.Xgithub = Xgithub;
window.customElements.define('github-card', Xgithub)
}
</script>
<script>
window.addEventListener('load', () => {
const inp = document.querySelector('#username');
const frm = document.querySelector('#create-card');
const output = document.querySelector('#cards');
frm.addEventListener('submit', (eve) => {
const user = inp.value;
let github = null;
eve.preventDefault();
if (user === '') { return false; }
github = document.createElement('github-card');
github.setAttribute('user', user);
output.innerHTML = '';
output.appendChild(github);
}, true);
});
</script>
</body>
</html>