Added interaction counts to posts
All checks were successful
/ weblog.lol (push) Successful in 10s

This commit is contained in:
Gordon Pedersen 2024-05-11 21:47:07 +10:00
parent b1c489e2e0
commit 78703ed570

View file

@ -121,13 +121,26 @@ customElements.define('fedi-social', FediSocial)
function fediverse() {
const data = JSON.parse(localStorage.getItem('fedi-social') || '{}')
document.querySelectorAll("a.external_url:not([href='{external_url}'])").forEach(el => {
document.querySelectorAll("a.external_url:not([href='{external_url}'])").forEach(async (el) => {
if(data.template){
href = data.template.replace("{uri}", el.href)
const orig_href = el.href
let href = data.template.replace("{uri}", orig_href)
el.href = href
try{
const res = await fetch(`https://monrepos.casa/api/v2/search?type=statuses&q=${orig_href}`, {
headers: {
'Authorization': 'Basic Ym90OjJuUmZhTGJ1c3cyaFhA'
}
})
const json = await res.json()
const status = json?.statuses?.find(s => s.uri == orig_href)
if(status) {
const innerHTML = `
<a href='${href}' target="_blank"><i class="fa fa-comment"></i></a>
<a href='${href}' target="_blank"><i class="fa fa-star"></i></a>
<a href='${href}' target="_blank"><i class="fa fa-retweet"></i></a>
<a href='${href}' target="_blank"><i class="fa fa-comment"></i> ${status?.replies_count}</a>
<a href='${href}' target="_blank"><i class="fa fa-star"></i> ${status?.favourites_count}</a>
<a href='${href}' target="_blank"><i class="fa fa-retweet"></i> ${status?.reblogs_count}</a>
`
const span = document.createElement('span')
@ -137,6 +150,11 @@ function fediverse() {
el.insertAdjacentElement('afterend', span)
el.remove()
}
}
catch(ex){
console.error(ex)
}
}
else {
el.addEventListener('click', ev =>{
ev.preventDefault()