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() {
|
function fediverse() {
|
||||||
const data = JSON.parse(localStorage.getItem('fedi-social') || '{}')
|
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){
|
if(data.template){
|
||||||
href = data.template.replace("{uri}", el.href)
|
const orig_href = el.href
|
||||||
const innerHTML = `
|
let href = data.template.replace("{uri}", orig_href)
|
||||||
<a href='${href}' target="_blank"><i class="fa fa-comment"></i></a>
|
el.href = href
|
||||||
<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 span = document.createElement('span')
|
try{
|
||||||
span.classList.add('fediverse')
|
const res = await fetch(`https://monrepos.casa/api/v2/search?type=statuses&q=${orig_href}`, {
|
||||||
span.innerHTML = innerHTML
|
headers: {
|
||||||
|
'Authorization': 'Basic Ym90OjJuUmZhTGJ1c3cyaFhA'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const json = await res.json()
|
||||||
|
const status = json?.statuses?.find(s => s.uri == orig_href)
|
||||||
|
|
||||||
el.insertAdjacentElement('afterend', span)
|
if(status) {
|
||||||
el.remove()
|
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 {
|
else {
|
||||||
el.addEventListener('click', ev =>{
|
el.addEventListener('click', ev =>{
|
||||||
|
|
Loading…
Reference in a new issue