You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB
JavaScript

var misskey_host = ""
err = document.getElementById('err');
browser.storage.sync.get('value').then(
result => misskey_host = result.value,
err => misskey_host = default_host);
browser.storage.sync.get('instance').then(result => misskey_host = instance)
browser.tabs
.query({ currentWindow: true, active: true })
.then(tabs => update_data(tabs[0].url), err => document.getElementById('err').innerHTML=err);
function display_notes(data){
n = document.getElementById('notes');
n.innerHTML = "";
update = "";
if (data.length == 0){
update="<p>No data</p>"
}
for (var i = 0; i < data.length; i++){
note = data[i];
if (note['user']['host'] == null){
note['user']['host'] = misskey_host;
}
update += "<div class='note'>";
update +="<div class='poster'><img src='"+note['user']['avatarUrl'];
update+="'><strong>";
update+= note['user']['username']+"@"+note['user']['host']+"</strong></div>";
if (!note['url']){
note['url'] = note['uri'];
}
update +="<p>"+note['text']+"<br><a href='"+note['url']+"'>link</a> "
if (note['renoteCount'] || note['repliesCount']){
update +=note['renoteCount']+" renotes "+note['repliesCount']+" replies"
}
update += "</p></div><hr>"
}
n.innerHTML = update;
document.getElementById('err').style.display="none";
}
async function update_data(url){
document.getElementById('err').innerHTML = "Getting notes for:" + url +"<br>From: "+misskey_host;
data = JSON.stringify({
"query":url,
"limit":100,
});
await fetch(misskey_host +"/api/notes/search",{
method:'POST',
body:data,
headers:{"Content-Type":"application/json"}
}).then(resp => resp.json()).then(data => display_notes(data));
}