11/* eslint no-undef: 0 */
22import widgetStyle from './style.js' ;
33import nFormatter from './format.js' ;
4+ import escapeHtml from './escape.js' ;
45
56const template = document . createElement ( 'template' ) ;
67
@@ -19,13 +20,13 @@ class myCard extends HTMLElement {
1920 this . _shadowRoot . append ( template . content . cloneNode ( true ) ) ;
2021 }
2122
22- get observedAttribute ( ) {
23+ static get observedAttributes ( ) {
2324 return [ 'data-theme' ] ;
2425 }
2526
2627 attributeChangedCallback ( attr , oldValue , newValue ) {
27- if ( attr === 'data-theme' && oldValue !== newValue && newValue !== '' ) {
28- this [ attr ] = newValue ;
28+ if ( attr === 'data-theme' && oldValue !== newValue ) {
29+ this . setTheme ( newValue ) ;
2930 }
3031 }
3132
@@ -34,11 +35,6 @@ class myCard extends HTMLElement {
3435 const cardTemplate = this . createCard ( response ) ;
3536 this . _shadowRoot . querySelector ( '.card' ) . innerHTML = cardTemplate ;
3637 } ) ;
37-
38- if ( this . getAttribute ( 'data-theme' ) ) {
39- const theme = this . getAttribute ( 'data-theme' ) ;
40- this . setTheme ( theme ) ;
41- }
4238 }
4339
4440 setTheme ( theme ) {
@@ -62,31 +58,37 @@ class myCard extends HTMLElement {
6258 }
6359
6460 createCard ( user ) {
61+ const login = escapeHtml ( user . login ) ;
62+ const htmlUrl = escapeHtml ( user . html_url ) ;
63+ const name = escapeHtml ( user . name ) ;
64+ const bio = escapeHtml ( user . bio ?? '' ) ;
6565 return `
6666 <div class="cover"></div>
6767 <div class="card-wrapper">
68- <a href="https://github.com/${ user . login } " target="_blank" rel="noopener"><img id="github-logo" src="https://i.ibb.co/frv5pB3/github-logo.png" alt="github-logo" border="0"></a>
68+ <a href="https://github.com/${ login } " target="_blank" rel="noopener"><img id="github-logo" src="https://i.ibb.co/frv5pB3/github-logo.png" alt="github-logo" border="0"></a>
6969 <div class="card-header">
70- <div class="card-img-wrapper"><img src="https://avatars.githubusercontent.com/${ user . login } "/></div>
71- <h1><a class="card-title" href="${ user . html_url } " target="_blank" rel="noopener">${ user . name } </a></h1>
72- <div class="card-responsename"><a href="${ user . html_url } " target="_blank" rel="noopener">@${ user . login } </a></div>
73- <p class="card-desc">${ user . bio ?? '' } </p>
70+ <div class="card-img-wrapper"><img src="https://avatars.githubusercontent.com/${ login } " alt=" ${ name } "/></div>
71+ <h1><a class="card-title" href="${ htmlUrl } " target="_blank" rel="noopener">${ name } </a></h1>
72+ <div class="card-responsename"><a href="${ htmlUrl } " target="_blank" rel="noopener">@${ login } </a></div>
73+ <p class="card-desc">${ bio } </p>
7474 <div class="card-footer">
7575 <div class="footer-box">
7676 <div class="box-wrapper">
7777 <div class="count">${ nFormatter ( user . followers ) } </div>
7878 <div class="box-text">Followers</div>
79- </div>
79+ </div>
8080 <div class="box-wrapper">
8181 <div class="count">${ nFormatter ( user . following ) } </div>
8282 <div class="box-text">Following</div>
83- </div>
83+ </div>
8484 <div class="box-wrapper">
8585 <div class="count">${ nFormatter ( user . public_repos ) } </div>
8686 <div class="box-text">Repositories</div>
8787 </div>
8888 </div>
8989 </div>
90+ </div>
91+ </div>
9092 ` ;
9193 }
9294}
0 commit comments