-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubInfos.js
40 lines (33 loc) · 1.01 KB
/
githubInfos.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
class GithubInfos extends HTMLElement {
constructor() {
super();
}
static get observedAttributes() { return ["repository"]; }
attributeChangedCallback(name, oldValue, newValue) {
if (name == "repository" && oldValue != newValue) {
fetch(`https://api.github.com/repos/${newValue}`)
.then(response => response.json())
.then(data => this.render(data));
}
}
connectedCallback() { }
adoptedCallback() { }
disconnectedCallback() { }
render(data) {
const content = `
<header>
<a href="${data.html_url || '#'}" target="_blank">${data.name || ''}</a>
<a href="${data.owner.html_url || '#'}" target="_blank">@${data.owner.login || ''}</a>
</header>
<p>${data.description || ''}</p>
<hr>
<div>
<span>${data.subscribers_count} watchers</span>
<span>${data.watchers} stars</span>
<span>${data.forks} forks</span>
</div>
`;
this.innerHTML = content;
}
}
customElements.define('github-infos', GithubInfos);