-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodewars-stats.js
More file actions
103 lines (84 loc) · 2.77 KB
/
codewars-stats.js
File metadata and controls
103 lines (84 loc) · 2.77 KB
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
class YourNewComponentNameDB extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.userName = "Della%20Bella%20";
this.userData = {};
}
connectedCallback() {
this.fetchUserData()
.then(() => {
this.render();
})
.catch((error) => {
console.error("Could not fetch Codewars data:", error);
});
}
async fetchUserData() {
const response = await fetch(
`https://www.codewars.com/api/v1/users/${this.userName}`
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
this.userData = await response.json();
}
render() {
// 3. Replace EVERYTHING inside the backticks (`) below
this.shadowRoot.innerHTML = `
<style>
:host {
display: block; /* Already block, which is needed */
padding: 1.5em;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: #ffffff;
color: #333;
border: 1px solid #e0e0e0;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
box-sizing: border-box;
/* --- Centering Styles --- */
max-width: 600px; /* Or choose a width like 'width: 80%;' or 'width: 500px;' */
margin-left: auto;
margin-right: auto;
/* --- End Centering Styles --- */
margin-bottom: 1em; /* Keep the space below */
}
/* Add other styles for elements inside your component */
h2 {
margin-top: 0;
color: #111;
}
p {
line-height: 1.5;
}
p > br {
display: none;
}
</style>
<div>
<h2>My New Codewars Component!</h2>
<p>
<!-- 5. Access data from this.userData and display it -->
Username: ${this.userData.username}</p>
<br>
Completed Challenges: ${this.userData.codeChallenges?.totalCompleted}
</p>
<p>
Skills: ${this.userData.skills}
</p><br>
<p>
points Gain: ${this.userData.honor}
</p><br>
<p>
Completed Kata: ${this.userData.codeChallenges.totalCompleted}
</p>
<!-- Add more HTML elements to display other data -->
</div>
`;
}
// --- END OF THE PART YOU WILL CHANGE ---
}
// 2. Define the custom HTML tag name (must include a hyphen)
// and link it to your new class name. RENAME BOTH parts below.
customElements.define("katas-gis-db", YourNewComponentNameDB);