This commit is contained in:
parent
b1c489e2e0
commit
78703ed570
1 changed files with 30 additions and 12 deletions
|
@ -121,21 +121,39 @@ 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 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>
|
||||
`
|
||||
const orig_href = el.href
|
||||
let href = data.template.replace("{uri}", orig_href)
|
||||
el.href = href
|
||||
|
||||
const span = document.createElement('span')
|
||||
span.classList.add('fediverse')
|
||||
span.innerHTML = innerHTML
|
||||
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)
|
||||
|
||||
el.insertAdjacentElement('afterend', span)
|
||||
el.remove()
|
||||
if(status) {
|
||||
const innerHTML = `
|
||||
<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')
|
||||
span.classList.add('fediverse')
|
||||
span.innerHTML = innerHTML
|
||||
|
||||
el.insertAdjacentElement('afterend', span)
|
||||
el.remove()
|
||||
}
|
||||
}
|
||||
catch(ex){
|
||||
console.error(ex)
|
||||
}
|
||||
}
|
||||
else {
|
||||
el.addEventListener('click', ev =>{
|
||||
|
|
Loading…
Reference in a new issue