div.thread-parent { border: 2px solid rgba(0, 0, 0, 0.5); min-height: 300px; } a.thread-child { display: flex; align-items: center; justify-content: flex-start; border: 1px solid rgba(255, 255, 255, 0.3); padding: 0 0 0 5px; border-radius: 5px; } div.thread-profile-image { flex-basis: 40px; margin-right: 5px; height: 40px; } div.thread-profile-image img { object-fit: cover; width: 32px; height: 32px; aspect-ratio: 1/1; border-radius: 50%; margin: 0 auto; } div.thread-title { flex-basis: 80%; font-weight: 550; opacity: 0.8; color: beige; } div.thread-notif { display: flex; flex-direction: column; font-size: 0.9rem; font-weight: 400; opacity: 0.7; margin: 3px; color: white; margin-left: auto; align-items: flex-end; line-height: 0.9rem; flex: 0 0 auto; opacity: 0.4; } window.addEventListener('load', async() => { const parent_widget_thread = document.querySelector('.thread-parent'); await loadThread(); async function loadThread() { await initFunctions(['supabase', 'moment']); let { data, error } = await supabase.from('sth_threads').select('id, title, date, images, category_id(title), user_id(prof_img, country)').order('date', {ascending: false}); if (error) { window.alert(`${error.message}`); return; } data.forEach(async(item) => { // getting comment counts let comment_count = 0; let data = await supabase.from('sth_comments').select('*', { count: 'exact', head: true }).eq('thread_id', item.id); if(data.count) comment_count = data.count; parent_widget_thread.innerHTML += `<a id=${item.id} class="thread-child" target='_blank' href="https://storehaccounts.blogspot.com/p/thread-viewer.html?thread=${btoa(item.id)}"><div class="thread-profile-image"><img src="${item.user_id.prof_img}"><img src="${item.user_id.country == "Anonymous" ? `https://i.ibb.co/VpHBRVpr/image.png` : `https://flagcdn.com/w320/${item.user_id.country.toLowerCase()}.png`}" style=" position: relative; top: -20px; width: 20px; border-radius: 0; object-fit: contain; "> </div> <div class="thread-title"> <p>${item.title}</p> </div> <div class="thread-notif"> <span>${moment(item.date).fromNow()}</span> ${comment_count == 0 ? ``: `<span>${countComment(comment_count)}</span>`} </div> </a>`; }); } function countComment(num) { // returns the comment and number return num > 1 ? `${num} comment`: `${num} comments`; } }, false);