Compare commits

...

1 commit

Author SHA1 Message Date
2b4d8bbe1c Webfinger draft 2024-03-18 21:21:04 -05:00
2 changed files with 43 additions and 39 deletions

View file

@ -130,8 +130,8 @@
<script src="/scripts/accessibility.js"></script> <script src="/scripts/accessibility.js"></script>
<script> <script>
let game = { let game = {
USER_ID: "Abg3KCIlHi1Q2Gzx0y", FOLLOWERS_LINK: "",
INSTANCE: "local.abtmtr.link" FOLLOWING_LINK: ""
}; };
</script> </script>
<script src="./script.js"></script> <script src="./script.js"></script>

View file

@ -10,6 +10,8 @@ function escapeHtml(unsafe)
.replace(/<\/?object\/?>/g, ""); .replace(/<\/?object\/?>/g, "");
} }
const n = ()=>null;
const el_id_user = document.querySelector("#user"); const el_id_user = document.querySelector("#user");
const el_id_instance = document.querySelector("#instance"); const el_id_instance = document.querySelector("#instance");
const el_id_whoami = document.querySelector("#whoami"); const el_id_whoami = document.querySelector("#whoami");
@ -33,29 +35,31 @@ async function verify() {
const instance = el_id_instance.value.replace(/@/gim, ""); const instance = el_id_instance.value.replace(/@/gim, "");
el_id_user.value = username; el_id_user.value = username;
el_id_instance.value = instance; el_id_instance.value = instance;
el_id_submitwhoamiFollowers.disabled = true;
el_id_submitwhoamiFollowing.disabled = true;
if (username.length < 1) return null; if (username.length < 1) return null;
if (instance.length < 1) return null; if (instance.length < 1) return null;
let user_req; const webf_req = await fetch(`https://${instance}/.well-known/webfinger?resource=acct:${username}@${instance}`)
try { .catch(n); // who cares
user_req = await fetch(`https://${instance}/api/v1/accounts/lookup?acct=${username}`); if (webf_req == null) return null;
} catch (err) { const webf_json = await webf_req.json();
return null; const user_req = await fetch(webf_json.links.find(x => x.type == "application/activity+json").href, {
} headers: {"Accept": "application/activity+json"}
})
.catch(n); // who cares
if (user_req == null) return null;
const user_json = await user_req.json(); const user_json = await user_req.json();
el_id_submitwhoamiFollowers.disabled = false; return {
el_id_submitwhoamiFollowing.disabled = false; FOLLOWERS_LINK: user_json.followers,
if (user_req.ok) return { FOLLOWING_LINK: user_json.following
USER_ID: user_json.id, }
INSTANCE: instance
};
else return null;
} }
el_id_submitwhoamiFollowers.addEventListener("click", async (e) => { el_id_submitwhoamiFollowers.addEventListener("click", async (e) => {
el_id_errorwhoami.innerHTML = ""; el_id_errorwhoami.innerHTML = "";
el_id_submitwhoamiFollowers.disabled = true;
el_id_submitwhoamiFollowing.disabled = true;
const result = await verify(); const result = await verify();
el_id_submitwhoamiFollowers.disabled = false;
el_id_submitwhoamiFollowing.disabled = false;
if (result == null) { if (result == null) {
el_id_errorwhoami.innerHTML = "Invalid user!"; el_id_errorwhoami.innerHTML = "Invalid user!";
return false; return false;
@ -76,10 +80,7 @@ el_id_submitwhoamiFollowing.addEventListener("click", async (e) => {
el_id_errorwhoami.innerHTML = "Invalid user!"; el_id_errorwhoami.innerHTML = "Invalid user!";
return false; return false;
} }
game = { game = result;
...game,
...result
};
gamemodeFollowers = false; gamemodeFollowers = false;
getFollowing(); getFollowing();
@ -103,10 +104,10 @@ let lastId = "";
let selectedUsers = []; let selectedUsers = [];
function renderNameHTML(name, user) { function renderNameHTML(name, user) {
return escapeHtml(name).replace(/:([a-z0-9_-]+?):/gim, (m, p1) => { return escapeHtml(name).replace(/(:[a-z0-9_-]+?:)/gim, (m, p1) => {
const emoji = user.emojis.find(x => x.shortcode == p1); const emoji = user.emojis.find(x => x.name == p1);
if (emoji == null) return null; if (emoji == null) return null;
return `<img src="${emoji.url}" width="16" height="16" title=":${emoji.shortcode}:" />`; return `<img src="${emoji.icon.url}" width="16" height="16" title="${emoji.name}" />`;
}); });
} }
@ -119,16 +120,32 @@ async function getFollowers(dontLoadNew = false) {
let out; let out;
if (!dontLoadNew) { if (!dontLoadNew) {
el_id_loadingfollowers.innerHTML = `Retrieving followers... Please wait.`; el_id_loadingfollowers.innerHTML = `Retrieving followers... Please wait.`;
res = await fetch(`https://${game.INSTANCE}/api/v1/accounts/${game.USER_ID}/followers${lastId.length > 0 ? `?max_id=${lastId}` : ""}`); res = await fetch(game.FOLLOWERS_LINK);
out = await res.json(); out = await res.json();
} }
el_id_submitfollowers.disabled = false; el_id_submitfollowers.disabled = false;
el_id_morefollowers.disabled = false; el_id_morefollowers.disabled = false;
if (dontLoadNew) return false; if (dontLoadNew) return false;
if (out.length < 1) { if (typeof out.first === "object" && Array.isArray(out.first.orderedItems) && out.first.orderedItems.length < 1) {
el_id_loadingfollowers.innerHTML = `No followers found.`; el_id_loadingfollowers.innerHTML = `No followers found.`;
return false; return false;
} }
const unsanitizedUsers = await Promise.all(out.first.orderedItems.map(async (x) => {
const fetcher = await fetch(x, {
headers: {"Accept": "application/activity+json"}
}).catch(n);
return
}));
console.log(unsanitizedUsers);
userList.push(...unsanitizedUsers.map(user => ({
fqn: user.preferredUsername + "@" + new URL(user.url).hostname,
avatar: user.icon.url,
display_name: user.name,
emojis: user.tag.filter(x => x.type == "Emoji"),
fields: user.attachment,
note: user.summary,
url: user.url
})));
el_id_listfollowers.hidden = false; el_id_listfollowers.hidden = false;
el_id_listfollowers.innerHTML += out.reduce((pv, cuser) => { el_id_listfollowers.innerHTML += out.reduce((pv, cuser) => {
return pv + `<tr> return pv + `<tr>
@ -142,19 +159,6 @@ async function getFollowers(dontLoadNew = false) {
<td class="followers_namelabel">@${cuser.fqn || cuser.acct}</td> <td class="followers_namelabel">@${cuser.fqn || cuser.acct}</td>
</tr>` </tr>`
}, ""); }, "");
userList.push(...out.map(user => ({
fqn: user.fqn || user.acct,
avatar: user.avatar,
bot: user.bot,
created_at: user.created_at,
display_name: user.display_name,
emojis: user.emojis,
fields: user.fields,
id: user.id,
note: user.note,
username: user.url,
username: user.username
})));
lastId = userList.at(-1).id; lastId = userList.at(-1).id;
selectboxes = Array.from(el_id_listfollowers.querySelectorAll(".follower_checkbox")); selectboxes = Array.from(el_id_listfollowers.querySelectorAll(".follower_checkbox"));
selectboxes.forEach(x => x.addEventListener("change", checkSelectedAmtFollowers)); selectboxes.forEach(x => x.addEventListener("change", checkSelectedAmtFollowers));