@@ -5,10 +5,10 @@ const iconUrl = (href) => {
55 return `https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${ origin } &size=32`
66}
77
8- const addElm = ( parent , tag , content , attributes ) => {
8+ const addElm = ( parent , tag , text , attributes ) => {
99 const elm = document . createElement ( tag )
10- if ( content ) {
11- elm . innerHTML = content
10+ if ( text ) {
11+ elm . textContent = text
1212 }
1313 if ( attributes ) {
1414 Object . entries ( attributes ) . forEach ( ( [ key , value ] ) => {
@@ -34,12 +34,18 @@ const renderNode =
3434 parentUl . className = 'flat-bookmark-structure'
3535 }
3636
37- const icon = `<img src="${ iconUrl ( href ) } " alt="${ title . substring (
38- 0 ,
39- 1
40- ) } " />`
37+ const link = document . createElement ( 'a' )
38+ link . href = href
4139
42- addElm ( li , 'a' , `${ icon } ${ title } ` , { href } )
40+ const icon = document . createElement ( 'img' )
41+ icon . src = iconUrl ( href )
42+ icon . alt = title . substring ( 0 , 1 )
43+ link . append ( icon )
44+
45+ const text = document . createTextNode ( ` ${ title } ` )
46+ link . append ( text )
47+
48+ li . append ( link )
4349 }
4450 }
4551
@@ -95,10 +101,10 @@ const initImage = async () => {
95101 if ( ! isBookmarksBarHidden ( ) ) {
96102 hideImage ( )
97103 } else {
98- const image = JSON . parse (
99- window . localStorage . getItem ( IMAGE_KEY_NAME ) || '{}'
100- )
101- if ( image && image . created > Date . now ( ) - IMAGE_VALID_MS ) {
104+ let image = JSON . parse ( window . localStorage . getItem ( IMAGE_KEY_NAME ) || '{}' )
105+ const hasImage =
106+ image && image . attribution && typeof image . attribution !== 'string'
107+ if ( hasImage && image . created > Date . now ( ) - IMAGE_VALID_MS ) {
102108 showImage ( image )
103109 } else {
104110 const utmParams =
@@ -119,10 +125,13 @@ const initImage = async () => {
119125 . join ( ' ' )
120126 const userLink = `${ user ?. links ?. html } ${ utmParams } `
121127
122- const attribution = `Photo by <a href="${ userLink } ">${ userFullName } </a> on <a href="${ imageLink } ">Unsplash</a>`
123128 const imageData = {
124129 url : imageUrl ,
125- attribution,
130+ attribution : {
131+ userLink,
132+ userFullName,
133+ imageLink,
134+ } ,
126135 blurhash,
127136 created : Date . now ( ) ,
128137 }
@@ -167,7 +176,18 @@ const showImage = ({ url, attribution, blurhash }) => {
167176
168177 const attributionElm = document . createElement ( 'p' )
169178 attributionElm . id = 'image-attribution'
170- attributionElm . innerHTML = attribution
179+ const userLink = document . createElement ( 'a' )
180+ userLink . href = attribution . userLink
181+ userLink . textContent = attribution . userFullName
182+ const imageLink = document . createElement ( 'a' )
183+ imageLink . href = attribution . imageLink
184+ imageLink . textContent = 'Unsplash'
185+ attributionElm . append (
186+ document . createTextNode ( 'Photo by ' ) ,
187+ userLink ,
188+ document . createTextNode ( ' on ' ) ,
189+ imageLink
190+ )
171191 document . body . appendChild ( attributionElm )
172192}
173193
0 commit comments