Thread viewer for Bluesky

load gifs on click

+47
embed_component.js
··· 125 126 a.append(box); 127 128 return a; 129 } 130 131 /** @param {FeedGeneratorRecord} feedgen, @returns {HTMLElement} */
··· 125 126 a.append(box); 127 128 + if (hostname == 'media.tenor.com') { 129 + a.addEventListener('click', (e) => { 130 + e.preventDefault(); 131 + this.displayGIFInline(a, embed); 132 + }); 133 + } 134 + 135 return a; 136 + } 137 + 138 + /** @param {HTMLElement} a, @param {RawLinkEmbed | InlineLinkEmbed} embed */ 139 + 140 + displayGIFInline(a, embed) { 141 + let gifDiv = $tag('div.gif'); 142 + let img = $tag('img', { src: embed.url }, HTMLImageElement); 143 + img.style.opacity = '0'; 144 + img.style.maxHeight = '200px'; 145 + gifDiv.append(img); 146 + a.replaceWith(gifDiv); 147 + 148 + img.addEventListener('load', (e) => { 149 + if (img.naturalWidth > img.naturalHeight) { 150 + img.style.maxHeight = '200px'; 151 + } else { 152 + img.style.maxWidth = '200px'; 153 + img.style.maxHeight = '400px'; 154 + } 155 + 156 + img.style.opacity = ''; 157 + }); 158 + 159 + let staticPic; 160 + 161 + if (typeof embed.thumb == 'string') { 162 + staticPic = embed.thumb; 163 + } else { 164 + staticPic = `https://cdn.bsky.app/img/avatar/plain/${this.post.author.did}/${embed.thumb.ref.$link}@jpeg`; 165 + } 166 + 167 + img.addEventListener('click', (e) => { 168 + if (img.classList.contains('static')) { 169 + img.src = embed.url; 170 + img.classList.remove('static'); 171 + } else { 172 + img.src = staticPic; 173 + img.classList.add('static'); 174 + } 175 + }); 176 } 177 178 /** @param {FeedGeneratorRecord} feedgen, @returns {HTMLElement} */
+2
models.js
··· 650 651 this.url = json.external.uri; 652 this.title = json.external.title; 653 } 654 } 655 ··· 718 this.url = json.external.uri; 719 this.title = json.external.title; 720 this.description = json.external.description; 721 } 722 } 723
··· 650 651 this.url = json.external.uri; 652 this.title = json.external.title; 653 + this.thumb = json.external.thumb; 654 } 655 } 656 ··· 719 this.url = json.external.uri; 720 this.title = json.external.title; 721 this.description = json.external.description; 722 + this.thumb = json.external.thumb; 723 } 724 } 725
+9
style.css
··· 640 color: #aaa; 641 } 642 643 .post .stats { 644 font-size: 10pt; 645 color: #666;
··· 640 color: #aaa; 641 } 642 643 + .post div.gif img { 644 + user-select: none; 645 + -webkit-user-select: none; 646 + } 647 + 648 + .post div.gif img.static { 649 + opacity: 0.75; 650 + } 651 + 652 .post .stats { 653 font-size: 10pt; 654 color: #666;