Update profile embed, fix height bug

This commit is contained in:
Daniel Supernault 2024-04-20 05:59:01 -06:00
parent cde17f5af7
commit a54b4fb038
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -76,21 +76,33 @@
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
let parent = document.querySelector('.embed-row'); let parent = document.querySelector('.embed-row');
res.filter(post => post.pf_type == 'photo' && !post.sensitive && post.visibility === 'public')
res.filter(res => res.pf_type == 'photo' && !res.sensitive && res.visibility === 'public')
.slice(0, 9) .slice(0, 9)
.forEach(post => { .forEach((post, idx) => {
let mediaUrl = post.media_attachments[0].preview_url ? post.media_attachments[0].preview_url : post.media_attachments[0].url; let mediaUrl = post.media_attachments[0].preview_url ? post.media_attachments[0].preview_url : post.media_attachments[0].url;
let el = document.createElement('template') let html = `<div class="col-4 mt-2 px-0"><a class="card info-overlay card-md-border-0 px-1 shadow-none" href="${post.url}" target="_blank"><div class="square"><div class="square-content" style="background-image: url('${mediaUrl}')"></div></div></a></div>`;
el.innerHTML = `<div class="col-4 mt-2 px-0"><a class="card info-overlay card-md-border-0 px-1 shadow-none" href="${post.url}" target="_blank"><div class="square"><div class="square-content" style="background-image: url('${mediaUrl}')"></div></div></a></div>`; let el = document.createElement('div');
parent.append(el.content); el.innerHTML = html;
parent.appendChild(el.firstChild);
});
}) })
}).then(() => { window.addEventListener("message", e => {
window.addEventListener("message",e=>{const t=e.data||{};window.parent&&"setHeight"===t.type&&window.parent.postMessage({type:"setHeight",id:t.id,height:document.getElementsByTagName("html")[0].scrollHeight},"*")}); const t = e.data || {};
if (window.parent && t.type === 'setHeight') {
updateHeight(t.id)
}
});
function updateHeight(id) {
setTimeout(() => { setTimeout(() => {
window.addEventListener("message",e=>{const t=e.data||{};window.parent&&"setHeight"===t.type&&window.parent.postMessage({type:"setHeight",id:t.id,height:document.getElementsByTagName("html")[0].scrollHeight},"*")}); window.parent.postMessage({
}, 5000); type: 'setHeight',
}) id: id,
height: document.documentElement.scrollHeight
}, "*");
}, 2500)
}
</script> </script>
</body> </body>
</html> </html>