|
|
|
@ -10,16 +10,15 @@ function escapeHtml(unsafe)
|
|
|
|
|
.replace(/<\/?object\/?>/g, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const n=x=>null;
|
|
|
|
|
const n = ()=>null;
|
|
|
|
|
|
|
|
|
|
const el_id_user = document.querySelector("#user");
|
|
|
|
|
const el_id_instance = document.querySelector("#instance");
|
|
|
|
|
const el_id_whoami = document.querySelector("#whoami");
|
|
|
|
|
const el_id_submitwhoamiFollowers = document.querySelector("#submitwhoami_followers");
|
|
|
|
|
const el_id_submitwhoamiFollowing = document.querySelector("#submitwhoami_following");
|
|
|
|
|
const el_id_submitwhoamiManual = document.querySelector("#submitwhoami_manual");
|
|
|
|
|
const el_id_errorwhoami = document.querySelector("#errorwhoami");
|
|
|
|
|
let gamemodeFollowers = "";
|
|
|
|
|
let gamemodeFollowers;
|
|
|
|
|
|
|
|
|
|
el_id_user.addEventListener("input", (e) => {
|
|
|
|
|
console.log(e);
|
|
|
|
@ -38,79 +37,53 @@ async function verify() {
|
|
|
|
|
el_id_instance.value = instance;
|
|
|
|
|
if (username.length < 1) return null;
|
|
|
|
|
if (instance.length < 1) return null;
|
|
|
|
|
|
|
|
|
|
// webfinger domain delegation
|
|
|
|
|
const domain = await fetch(`https://${instance}/.well-known/webfinger?resource=acct:${username}@${instance}`).catch(n);
|
|
|
|
|
if (domain == null || !domain.ok) return null;
|
|
|
|
|
const domain_json = (await domain.json());
|
|
|
|
|
const domain_url = new URL(domain_json.links.find(x=>x.type=="application/activity+json").href).hostname;
|
|
|
|
|
|
|
|
|
|
const user_req = await fetch(`https://${domain_url}/api/v1/accounts/lookup?acct=${username}`).catch(n);
|
|
|
|
|
if (user_req == null || !domain.ok) return null;
|
|
|
|
|
const webf_req = await fetch(`https://${instance}/.well-known/webfinger?resource=acct:${username}@${instance}`)
|
|
|
|
|
.catch(n); // who cares
|
|
|
|
|
if (webf_req == null) return null;
|
|
|
|
|
const webf_json = await webf_req.json();
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
window.localStorage.setItem("fediversemadness_game", JSON.stringify({ username, instance }));
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
USER_ID: user_json.id,
|
|
|
|
|
INSTANCE: domain_url
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function lookupUser() {
|
|
|
|
|
const lsGame = JSON.parse(window.localStorage.getItem("fediversemadness_game"));
|
|
|
|
|
if (lsGame != null) {
|
|
|
|
|
el_id_user.value = lsGame.username;
|
|
|
|
|
el_id_instance.value = lsGame.instance;
|
|
|
|
|
FOLLOWERS_LINK: user_json.followers,
|
|
|
|
|
FOLLOWING_LINK: user_json.following
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lookupUser();
|
|
|
|
|
|
|
|
|
|
async function doVerif() {
|
|
|
|
|
el_id_submitwhoamiFollowers.disabled = true;
|
|
|
|
|
el_id_submitwhoamiFollowing.disabled = true;
|
|
|
|
|
el_id_submitwhoamiManual.disabled = true;
|
|
|
|
|
game = await verify();
|
|
|
|
|
el_id_submitwhoamiFollowers.disabled = false;
|
|
|
|
|
el_id_submitwhoamiFollowing.disabled = false;
|
|
|
|
|
el_id_submitwhoamiManual.disabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
el_id_submitwhoamiFollowers.addEventListener("click", async (e) => {
|
|
|
|
|
el_id_errorwhoami.innerHTML = "";
|
|
|
|
|
await doVerif();
|
|
|
|
|
if (game == null) {
|
|
|
|
|
el_id_submitwhoamiFollowers.disabled = true;
|
|
|
|
|
el_id_submitwhoamiFollowing.disabled = true;
|
|
|
|
|
const result = await verify();
|
|
|
|
|
el_id_submitwhoamiFollowers.disabled = false;
|
|
|
|
|
el_id_submitwhoamiFollowing.disabled = false;
|
|
|
|
|
if (result == null) {
|
|
|
|
|
el_id_errorwhoami.innerHTML = "Invalid user!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
game = {
|
|
|
|
|
...game,
|
|
|
|
|
...result
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gamemodeFollowers = "followers";
|
|
|
|
|
startFollowers();
|
|
|
|
|
gamemodeFollowers = true;
|
|
|
|
|
getFollowers();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
el_id_submitwhoamiFollowing.addEventListener("click", async (e) => {
|
|
|
|
|
el_id_errorwhoami.innerHTML = "";
|
|
|
|
|
await doVerif();
|
|
|
|
|
if (game == null) {
|
|
|
|
|
const result = await verify();
|
|
|
|
|
if (result == null) {
|
|
|
|
|
el_id_errorwhoami.innerHTML = "Invalid user!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
game = result;
|
|
|
|
|
|
|
|
|
|
gamemodeFollowers = "following";
|
|
|
|
|
startFollowing();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
el_id_submitwhoamiManual.addEventListener("click", async (e) => {
|
|
|
|
|
el_id_errorwhoami.innerHTML = "";
|
|
|
|
|
await doVerif();
|
|
|
|
|
if (game == null) {
|
|
|
|
|
el_id_errorwhoami.innerHTML = "Invalid user!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gamemodeFollowers = "manual";
|
|
|
|
|
startManual();
|
|
|
|
|
gamemodeFollowers = false;
|
|
|
|
|
getFollowing();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Followers
|
|
|
|
@ -125,97 +98,70 @@ const el_id_deselectrandomfollowers = document.querySelector("#deselectrandomfol
|
|
|
|
|
const el_id_selectnofollowers = document.querySelector("#selectnofollowers");
|
|
|
|
|
const el_id_morefollowers = document.querySelector("#morefollowers");
|
|
|
|
|
const el_id_submitfollowers = document.querySelector("#submitfollowers");
|
|
|
|
|
const el_id_savehandlesfollowers = document.querySelector("#savehandlesfollowers");
|
|
|
|
|
const el_id_loadhandlesfollowers = document.querySelector("#loadhandlesfollowers");
|
|
|
|
|
let selectboxes = [];
|
|
|
|
|
let userList = [];
|
|
|
|
|
let lastId = "";
|
|
|
|
|
let selectedUsers = [];
|
|
|
|
|
|
|
|
|
|
function generateFollowersMap() {
|
|
|
|
|
const checks = Array.from(el_id_listfollowers.querySelectorAll(".follower_checkbox"));
|
|
|
|
|
let codeMap = {};
|
|
|
|
|
checks.forEach((checkbox) => {
|
|
|
|
|
const handle = checkbox.parentElement.parentElement.querySelector(".follower_checkname");
|
|
|
|
|
codeMap[handle.innerHTML] = checkbox.checked;
|
|
|
|
|
});
|
|
|
|
|
return codeMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function readFollowersMap(m) {
|
|
|
|
|
if (m == null) return;
|
|
|
|
|
const handles = Array.from(el_id_listfollowers.querySelectorAll(".follower_checkname"));
|
|
|
|
|
handles.forEach((handle) => {
|
|
|
|
|
const checkbox = handle.parentElement.querySelector(".follower_checkbox");
|
|
|
|
|
if (m[handle.innerHTML] != null)
|
|
|
|
|
checkbox.checked = m[handle.innerHTML];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderNameHTML(name, user) {
|
|
|
|
|
return `<span>${escapeHtml(name).replace(/:([a-z0-9_-]+?):/gim, (m, p1) => {
|
|
|
|
|
const emoji = user.emojis.find(x => x.shortcode == p1);
|
|
|
|
|
return escapeHtml(name).replace(/(:[a-z0-9_-]+?:)/gim, (m, p1) => {
|
|
|
|
|
const emoji = user.emojis.find(x => x.name == p1);
|
|
|
|
|
if (emoji == null) return null;
|
|
|
|
|
return `<img src="${emoji.url}" width="16" height="16" title=":${emoji.shortcode}:" />`;
|
|
|
|
|
})}</span>`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startFollowers(reload = true) {
|
|
|
|
|
goToState("followers");
|
|
|
|
|
if (reload) {
|
|
|
|
|
selectboxes = [];
|
|
|
|
|
userList = [];
|
|
|
|
|
lastId = "";
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
el_id_listfollowers.innerHTML = "";
|
|
|
|
|
}
|
|
|
|
|
getFollowers(!reload);
|
|
|
|
|
return `<img src="${emoji.icon.url}" width="16" height="16" title="${emoji.name}" />`;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getFollowers(dontLoadNew = false) {
|
|
|
|
|
el_id_whoami.hidden = true;
|
|
|
|
|
el_id_followers.hidden = false;
|
|
|
|
|
el_id_submitfollowers.disabled = true;
|
|
|
|
|
el_id_morefollowers.disabled = true;
|
|
|
|
|
let res;
|
|
|
|
|
let out;
|
|
|
|
|
if (!dontLoadNew) {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
el_id_submitfollowers.disabled = false;
|
|
|
|
|
el_id_morefollowers.disabled = 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.`;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
el_id_listfollowers.hidden = false;
|
|
|
|
|
out.forEach((cuser) => {
|
|
|
|
|
const element = document.createElement("tr");
|
|
|
|
|
element.innerHTML = `<td><input type="checkbox" class="follower_checkbox" checked onchange="checkSelectedAmtFollowers()" /></td>
|
|
|
|
|
<td><img src="${cuser.avatar}" width="32" height="32" /></td>
|
|
|
|
|
<td class="follower_namelabel">
|
|
|
|
|
<a href="${cuser.url}" target="_blank">
|
|
|
|
|
${renderNameHTML(cuser.display_name, cuser)}
|
|
|
|
|
</a>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="follower_namelabel follower_checkname">@${cuser.fqn}</td>`;
|
|
|
|
|
el_id_listfollowers.appendChild(element);
|
|
|
|
|
});
|
|
|
|
|
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,
|
|
|
|
|
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.innerHTML += out.reduce((pv, cuser) => {
|
|
|
|
|
return pv + `<tr>
|
|
|
|
|
<td><input type="checkbox" class="follower_checkbox" checked /></td>
|
|
|
|
|
<td><img src="${cuser.avatar}" width="32" height="32" /></td>
|
|
|
|
|
<td class="followers_namelabel">
|
|
|
|
|
<a href="${cuser.url}" target="_blank">
|
|
|
|
|
${renderNameHTML(cuser.display_name, cuser)}
|
|
|
|
|
</a>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="followers_namelabel">@${cuser.fqn || cuser.acct}</td>
|
|
|
|
|
</tr>`
|
|
|
|
|
}, "");
|
|
|
|
|
lastId = userList.at(-1).id;
|
|
|
|
|
selectboxes = Array.from(el_id_listfollowers.querySelectorAll(".follower_checkbox"));
|
|
|
|
|
selectboxes.forEach(x => x.addEventListener("change", checkSelectedAmtFollowers));
|
|
|
|
|
checkSelectedAmtFollowers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -245,17 +191,15 @@ el_id_selectnofollowers.addEventListener("click", () => {
|
|
|
|
|
checkSelectedAmtFollowers();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
el_id_savehandlesfollowers.addEventListener("click", () => window.localStorage.setItem("fediversemadness_followerssel", JSON.stringify(generateFollowersMap())));
|
|
|
|
|
el_id_loadhandlesfollowers.addEventListener("click", () => readFollowersMap(JSON.parse(window.localStorage.getItem("fediversemadness_followerssel"))));
|
|
|
|
|
|
|
|
|
|
el_id_morefollowers.addEventListener("click", () => getFollowers());
|
|
|
|
|
|
|
|
|
|
el_id_submitfollowers.addEventListener("click", () => {
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
console.log(selectedUsers);
|
|
|
|
|
selectboxes.forEach(({checked}, i) => {
|
|
|
|
|
if (checked) selectedUsers.push(userList.at(i));
|
|
|
|
|
});
|
|
|
|
|
if (selectedUsers.length < 2) {
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
el_id_loadingfollowers.innerHTML = `Selected user count is less than 2! (${selectboxes.filter(x => x.checked).length} selected)`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -278,49 +222,17 @@ const el_id_deselectrandomfollowing = document.querySelector("#deselectrandomfol
|
|
|
|
|
const el_id_selectnofollowing = document.querySelector("#selectnofollowing");
|
|
|
|
|
const el_id_morefollowing = document.querySelector("#morefollowing");
|
|
|
|
|
const el_id_submitfollowing = document.querySelector("#submitfollowing");
|
|
|
|
|
const el_id_savehandlesfollowing = document.querySelector("#savehandlesfollowing");
|
|
|
|
|
const el_id_loadhandlesfollowing = document.querySelector("#loadhandlesfollowing");
|
|
|
|
|
|
|
|
|
|
function generateFollowingMap() {
|
|
|
|
|
const checks = Array.from(el_id_listfollowing.querySelectorAll(".following_checkbox"));
|
|
|
|
|
let codeMap = {};
|
|
|
|
|
checks.forEach((checkbox) => {
|
|
|
|
|
const handle = checkbox.parentElement.parentElement.querySelector(".following_checkname");
|
|
|
|
|
codeMap[handle.innerHTML] = checkbox.checked;
|
|
|
|
|
});
|
|
|
|
|
return codeMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function readFollowingMap(m) {
|
|
|
|
|
if (m == null) return;
|
|
|
|
|
const handles = Array.from(el_id_listfollowing.querySelectorAll(".following_checkname"));
|
|
|
|
|
handles.forEach((handle) => {
|
|
|
|
|
const checkbox = handle.parentElement.querySelector(".following_checkbox");
|
|
|
|
|
if (m[handle.innerHTML] != null)
|
|
|
|
|
checkbox.checked = m[handle.innerHTML];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startFollowing(reload = true) {
|
|
|
|
|
goToState("following");
|
|
|
|
|
if (reload) {
|
|
|
|
|
selectboxes = [];
|
|
|
|
|
userList = [];
|
|
|
|
|
lastId = "";
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
el_id_listfollowing.innerHTML = "";
|
|
|
|
|
}
|
|
|
|
|
getFollowing(!reload);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getFollowing(dontLoadNew = false) {
|
|
|
|
|
el_id_whoami.hidden = true;
|
|
|
|
|
el_id_following.hidden = false;
|
|
|
|
|
el_id_submitfollowing.disabled = true;
|
|
|
|
|
el_id_morefollowing.disabled = true;
|
|
|
|
|
let res;
|
|
|
|
|
let out;
|
|
|
|
|
if (!dontLoadNew) {
|
|
|
|
|
el_id_loadingfollowing.innerHTML = `Retrieving following... Please wait.`;
|
|
|
|
|
res = await fetch(`https://${game.INSTANCE}/api/v1/accounts/${game.USER_ID}/following${lastId.length > 0 ? `?max_id=${lastId}` : ""}`);
|
|
|
|
|
res = await fetch(`https://${game.INSTANCE}/api/v1/accounts/${game.USER_ID}/following?limit=68${lastId.length > 0 ? `&max_id=${lastId}` : ""}`);
|
|
|
|
|
out = await res.json();
|
|
|
|
|
}
|
|
|
|
|
el_id_submitfollowing.disabled = false;
|
|
|
|
@ -331,18 +243,18 @@ async function getFollowing(dontLoadNew = false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
el_id_listfollowing.hidden = false;
|
|
|
|
|
out.forEach((cuser) => {
|
|
|
|
|
const element = document.createElement("tr");
|
|
|
|
|
element.innerHTML = `<td><input type="checkbox" class="following_checkbox" checked onchange="checkSelectedAmtFollowing()" /></td>
|
|
|
|
|
<td><img src="${cuser.avatar}" width="32" height="32" /></td>
|
|
|
|
|
<td class="following_namelabel">
|
|
|
|
|
<a href="${cuser.url}" target="_blank">
|
|
|
|
|
${renderNameHTML(cuser.display_name, cuser)}
|
|
|
|
|
</a>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="following_namelabel following_checkname">@${cuser.fqn}</td>`;
|
|
|
|
|
el_id_listfollowing.appendChild(element);
|
|
|
|
|
});
|
|
|
|
|
el_id_listfollowing.innerHTML += out.reduce((pv, cuser) => {
|
|
|
|
|
return pv + `<tr>
|
|
|
|
|
<td><input type="checkbox" class="follower_checkbox" checked /></td>
|
|
|
|
|
<td><img src="${cuser.avatar}" width="32" height="32" /></td>
|
|
|
|
|
<td class="following_namelabel">
|
|
|
|
|
<a href="${cuser.url}" target="_blank">
|
|
|
|
|
${renderNameHTML(cuser.display_name, cuser)}
|
|
|
|
|
</a>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="following_namelabel">@${cuser.fqn}</td>
|
|
|
|
|
</tr>`
|
|
|
|
|
}, "");
|
|
|
|
|
userList.push(...out.map(user => ({
|
|
|
|
|
fqn: user.fqn,
|
|
|
|
|
avatar: user.avatar,
|
|
|
|
@ -353,10 +265,12 @@ async function getFollowing(dontLoadNew = false) {
|
|
|
|
|
fields: user.fields,
|
|
|
|
|
id: user.id,
|
|
|
|
|
note: user.note,
|
|
|
|
|
url: user.url
|
|
|
|
|
username: user.url,
|
|
|
|
|
username: user.username
|
|
|
|
|
})));
|
|
|
|
|
lastId = userList.at(-1).id;
|
|
|
|
|
selectboxes = Array.from(el_id_listfollowing.querySelectorAll(".following_checkbox"));
|
|
|
|
|
selectboxes = Array.from(el_id_listfollowing.querySelectorAll(".follower_checkbox"));
|
|
|
|
|
selectboxes.forEach(x => x.addEventListener("change", checkSelectedAmtFollowing));
|
|
|
|
|
checkSelectedAmtFollowing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -386,17 +300,15 @@ el_id_selectnofollowing.addEventListener("click", () => {
|
|
|
|
|
checkSelectedAmtFollowing();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
el_id_savehandlesfollowing.addEventListener("click", () => window.localStorage.setItem("fediversemadness_followingsel", JSON.stringify(generateFollowingMap())));
|
|
|
|
|
el_id_loadhandlesfollowing.addEventListener("click", () => readFollowingMap(JSON.parse(window.localStorage.getItem("fediversemadness_followingsel"))));
|
|
|
|
|
|
|
|
|
|
el_id_morefollowing.addEventListener("click", () => getFollowing());
|
|
|
|
|
|
|
|
|
|
el_id_submitfollowing.addEventListener("click", () => {
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
console.log(selectedUsers);
|
|
|
|
|
selectboxes.forEach(({checked}, i) => {
|
|
|
|
|
if (checked) selectedUsers.push(userList.at(i));
|
|
|
|
|
});
|
|
|
|
|
if (selectedUsers.length < 2) {
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
el_id_loadingfollowing.innerHTML = `Selected user count is less than 2! (${selectboxes.filter(x => x.checked).length} selected)`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -407,122 +319,6 @@ function checkSelectedAmtFollowing() {
|
|
|
|
|
el_id_loadingfollowing.innerHTML = `${selectboxes.filter(x => x.checked).length} selected`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Manual
|
|
|
|
|
|
|
|
|
|
const el_id_manual = document.querySelector("#manual");
|
|
|
|
|
const el_id_loadingmanual = document.querySelector("#loadingmanual");
|
|
|
|
|
const el_id_listmanual = document.querySelector("#listmanual");
|
|
|
|
|
const el_id_listmanualvalues = document.querySelector("#listmanualvalues");
|
|
|
|
|
const el_id_selectallmanual = document.querySelector("#selectallmanual");
|
|
|
|
|
const el_id_selectrandommanual = document.querySelector("#selectrandommanual");
|
|
|
|
|
const el_id_deselectrandommanual = document.querySelector("#deselectrandommanual");
|
|
|
|
|
const el_id_selectnomanual = document.querySelector("#selectnomanual");
|
|
|
|
|
const el_id_manualuser = document.querySelector("#manualuser");
|
|
|
|
|
const el_id_manualinstance = document.querySelector("#manualinstance");
|
|
|
|
|
const el_id_moremanual = document.querySelector("#moremanual");
|
|
|
|
|
const el_id_submitmanual = document.querySelector("#submitmanual");
|
|
|
|
|
|
|
|
|
|
function startManual(reload = true) {
|
|
|
|
|
goToState("manual");
|
|
|
|
|
if (reload) {
|
|
|
|
|
selectboxes = [];
|
|
|
|
|
userList = [];
|
|
|
|
|
lastId = "";
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
el_id_listmanual.innerHTML = "";
|
|
|
|
|
}
|
|
|
|
|
checkSelectedAmtManual();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function addUserToManual() {
|
|
|
|
|
const username = el_id_manualuser.value.replace(/[^a-z0-9_]/gim, "");
|
|
|
|
|
const instance = el_id_manualinstance.value.replace(/@/gim, "");
|
|
|
|
|
el_id_manualuser.value = username;
|
|
|
|
|
el_id_manualinstance.value = instance;
|
|
|
|
|
if (username.length < 1) return null;
|
|
|
|
|
if (instance.length < 1) return null;
|
|
|
|
|
el_id_submitmanual.disabled = true;
|
|
|
|
|
el_id_moremanual.disabled = true;
|
|
|
|
|
el_id_loadingmanual.innerHTML = `Finding user...`;
|
|
|
|
|
let res = await fetch(`https://${game.INSTANCE}/api/v1/accounts/lookup?acct=${username}@${instance}`);
|
|
|
|
|
let out = await res.json();
|
|
|
|
|
el_id_submitmanual.disabled = false;
|
|
|
|
|
el_id_moremanual.disabled = false;
|
|
|
|
|
if (out.length < 1) {
|
|
|
|
|
el_id_loadingmanual.innerHTML = `No manual found.`;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
el_id_listmanual.hidden = false;
|
|
|
|
|
const element = document.createElement("tr");
|
|
|
|
|
element.innerHTML = `<td><input type="checkbox" class="manual_checkbox" checked onchange="checkSelectedAmtManual()" /></td>
|
|
|
|
|
<td><img src="${out.avatar}" width="32" height="32" /></td>
|
|
|
|
|
<td class="manual_namelabel">
|
|
|
|
|
<a href="${out.url}" target="_blank">
|
|
|
|
|
${renderNameHTML(out.display_name, out)}
|
|
|
|
|
</a>
|
|
|
|
|
</td>
|
|
|
|
|
<td class="manual_namelabel manual_checkname">@${out.fqn}</td>`;
|
|
|
|
|
el_id_listmanual.appendChild(element);
|
|
|
|
|
userList.push({
|
|
|
|
|
fqn: out.fqn,
|
|
|
|
|
avatar: out.avatar,
|
|
|
|
|
bot: out.bot,
|
|
|
|
|
created_at: out.created_at,
|
|
|
|
|
display_name: out.display_name,
|
|
|
|
|
emojis: out.emojis,
|
|
|
|
|
fields: out.fields,
|
|
|
|
|
id: out.id,
|
|
|
|
|
note: out.note,
|
|
|
|
|
url: out.url
|
|
|
|
|
});
|
|
|
|
|
selectboxes = Array.from(el_id_listmanual.querySelectorAll(".manual_checkbox"));
|
|
|
|
|
checkSelectedAmtManual();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
el_id_selectallmanual.addEventListener("click", () => {
|
|
|
|
|
selectboxes.forEach(x => x.checked = true);
|
|
|
|
|
checkSelectedAmtManual();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
el_id_selectrandommanual.addEventListener("click", () => {
|
|
|
|
|
const unselectedPick = selectboxes.filter(x => !x.checked);
|
|
|
|
|
const selected = unselectedPick[Math.floor(Math.random() * (unselectedPick.length - 1))];
|
|
|
|
|
if (selected == null) return;
|
|
|
|
|
selected.checked = true;
|
|
|
|
|
checkSelectedAmtManual();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
el_id_deselectrandommanual.addEventListener("click", () => {
|
|
|
|
|
const selectedPick = selectboxes.filter(x => x.checked);
|
|
|
|
|
const selected = selectedPick[Math.floor(Math.random() * (selectedPick.length - 1))];
|
|
|
|
|
if (selected == null) return;
|
|
|
|
|
selected.checked = false;
|
|
|
|
|
checkSelectedAmtManual();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
el_id_selectnomanual.addEventListener("click", () => {
|
|
|
|
|
selectboxes.forEach(x => x.checked = false);
|
|
|
|
|
checkSelectedAmtManual();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
el_id_moremanual.addEventListener("click", () => addUserToManual());
|
|
|
|
|
|
|
|
|
|
el_id_submitmanual.addEventListener("click", () => {
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
selectboxes.forEach(({checked}, i) => {
|
|
|
|
|
if (checked) selectedUsers.push(userList.at(i));
|
|
|
|
|
});
|
|
|
|
|
if (selectedUsers.length < 2) {
|
|
|
|
|
el_id_loadingmanual.innerHTML = `Selected user count is less than 2! (${selectboxes.filter(x => x.checked).length} selected)`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sortSelectedUsers();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function checkSelectedAmtManual() {
|
|
|
|
|
el_id_loadingmanual.innerHTML = `${selectboxes.filter(x => x.checked).length} selected`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Brackets
|
|
|
|
|
|
|
|
|
|
function shuf(array) {
|
|
|
|
@ -549,14 +345,14 @@ const el_id_gameUserOne = document.querySelector("#gameUserOne");
|
|
|
|
|
const el_id_gameUserOneImage = document.querySelector("#gameUserOneImage");
|
|
|
|
|
const el_id_gameUserOneName = document.querySelector("#gameUserOneName");
|
|
|
|
|
const el_id_gameUserOneId = document.querySelector("#gameUserOneId");
|
|
|
|
|
// const el_id_gameUserOneNote = document.querySelector("#gameUserOneNote");
|
|
|
|
|
// const el_id_gameUserOneFields = document.querySelector("#gameUserOneFields");
|
|
|
|
|
const el_id_gameUserOneNote = document.querySelector("#gameUserOneNote");
|
|
|
|
|
const el_id_gameUserOneFields = document.querySelector("#gameUserOneFields");
|
|
|
|
|
const el_id_gameUserTwo = document.querySelector("#gameUserTwo");
|
|
|
|
|
const el_id_gameUserTwoImage = document.querySelector("#gameUserTwoImage");
|
|
|
|
|
const el_id_gameUserTwoName = document.querySelector("#gameUserTwoName");
|
|
|
|
|
const el_id_gameUserTwoId = document.querySelector("#gameUserTwoId");
|
|
|
|
|
// const el_id_gameUserTwoNote = document.querySelector("#gameUserTwoNote");
|
|
|
|
|
// const el_id_gameUserTwoFields = document.querySelector("#gameUserTwoFields");
|
|
|
|
|
const el_id_gameUserTwoNote = document.querySelector("#gameUserTwoNote");
|
|
|
|
|
const el_id_gameUserTwoFields = document.querySelector("#gameUserTwoFields");
|
|
|
|
|
const el_id_gameSubmitLeft = document.querySelector("#gameSubmitLeft");
|
|
|
|
|
const el_id_gameSubmitRight = document.querySelector("#gameSubmitRight");
|
|
|
|
|
const el_id_gameBracketLevel = document.querySelector("#gameBracketLevel");
|
|
|
|
@ -567,16 +363,19 @@ let curDepth = 0;
|
|
|
|
|
let curFight = 0;
|
|
|
|
|
|
|
|
|
|
function sortSelectedUsers() {
|
|
|
|
|
goToState("game");
|
|
|
|
|
state = [];
|
|
|
|
|
curDepth = 0;
|
|
|
|
|
curFight = 0;
|
|
|
|
|
if (gamemodeFollowers)
|
|
|
|
|
el_id_followers.hidden = true;
|
|
|
|
|
else
|
|
|
|
|
el_id_following.hidden = true;
|
|
|
|
|
el_id_game.hidden = false;
|
|
|
|
|
state.push(chunk(shuf(selectedUsers), 2));
|
|
|
|
|
state.push([]);
|
|
|
|
|
prepareGameStage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prepareGameStage() {
|
|
|
|
|
el_id_gameSubmitLeft.disabled = true;
|
|
|
|
|
el_id_gameSubmitRight.disabled = true;
|
|
|
|
|
el_id_gameSubmitLeft.innerHTML = "Please wait...";
|
|
|
|
|
el_id_gameSubmitRight.innerHTML = "Please wait...";
|
|
|
|
|
el_id_gameUserOneImage.src = "";
|
|
|
|
@ -585,15 +384,15 @@ function prepareGameStage() {
|
|
|
|
|
el_id_gameBracketFight.innerHTML = "Round " + (curFight + 1);
|
|
|
|
|
const curSubStage = state[curDepth][curFight];
|
|
|
|
|
el_id_gameUserOneImage.src = curSubStage[0].avatar;
|
|
|
|
|
el_id_gameUserOneName.innerHTML = `<a href="${curSubStage[0].url}" target="_blank">${renderNameHTML(escapeHtml(curSubStage[0].display_name), curSubStage[0])}</a>`;
|
|
|
|
|
el_id_gameUserOneName.innerHTML = renderNameHTML(escapeHtml(curSubStage[0].display_name), curSubStage[0]);
|
|
|
|
|
el_id_gameUserOneId.innerHTML = "@" + curSubStage[0].fqn;
|
|
|
|
|
// el_id_gameUserOneNote.innerHTML = escapeHtml(curSubStage[0].note);
|
|
|
|
|
// el_id_gameUserOneFields.innerHTML = curSubStage[0].fields.reduce((pv, fields) => pv + `<tr><td>${escapeHtml(fields.name)}</td><td>${escapeHtml(fields.value)}</td></tr>`, "");
|
|
|
|
|
el_id_gameUserOneNote.innerHTML = escapeHtml(curSubStage[0].note);
|
|
|
|
|
el_id_gameUserOneFields.innerHTML = curSubStage[0].fields.reduce((pv, fields) => pv + `<tr><td>${escapeHtml(fields.name)}</td><td>${escapeHtml(fields.value)}</td></tr>`, "");
|
|
|
|
|
el_id_gameUserTwoImage.src = curSubStage[1].avatar;
|
|
|
|
|
el_id_gameUserTwoName.innerHTML = `<a href="${curSubStage[1].url}" target="_blank">${renderNameHTML(escapeHtml(curSubStage[1].display_name), curSubStage[1])}</a>`;
|
|
|
|
|
el_id_gameUserTwoName.innerHTML = renderNameHTML(escapeHtml(curSubStage[1].display_name), curSubStage[1]);
|
|
|
|
|
el_id_gameUserTwoId.innerHTML = "@" + curSubStage[1].fqn;
|
|
|
|
|
// el_id_gameUserTwoNote.innerHTML = escapeHtml(curSubStage[1].note);
|
|
|
|
|
// el_id_gameUserTwoFields.innerHTML = curSubStage[1].fields.reduce((pv, fields) => pv + `<tr><td>${escapeHtml(fields.name)}</td><td>${escapeHtml(fields.value)}</td></tr>`, "");
|
|
|
|
|
el_id_gameUserTwoNote.innerHTML = escapeHtml(curSubStage[1].note);
|
|
|
|
|
el_id_gameUserTwoFields.innerHTML = curSubStage[1].fields.reduce((pv, fields) => pv + `<tr><td>${escapeHtml(fields.name)}</td><td>${escapeHtml(fields.value)}</td></tr>`, "");
|
|
|
|
|
el_id_gameSubmitLeft.disabled = false;
|
|
|
|
|
el_id_gameSubmitRight.disabled = false;
|
|
|
|
|
el_id_gameSubmitLeft.innerHTML = "Pick " + "@" + curSubStage[0].fqn;
|
|
|
|
@ -642,94 +441,44 @@ const el_id_winnerUser = document.querySelector("#winnerUser");
|
|
|
|
|
const el_id_winnerUserImage = document.querySelector("#winnerUserImage");
|
|
|
|
|
const el_id_winnerUserName = document.querySelector("#winnerUserName");
|
|
|
|
|
const el_id_winnerUserId = document.querySelector("#winnerUserId");
|
|
|
|
|
// const el_id_winnerUserNote = document.querySelector("#winnerUserNote");
|
|
|
|
|
// const el_id_winnerUserFields = document.querySelector("#winnerUserFields");
|
|
|
|
|
const el_id_winnerUserNote = document.querySelector("#winnerUserNote");
|
|
|
|
|
const el_id_winnerUserFields = document.querySelector("#winnerUserFields");
|
|
|
|
|
const el_id_winnermessage = document.querySelector("#winnermessage");
|
|
|
|
|
const el_id_winnerusers = document.querySelector("#winnerusers");
|
|
|
|
|
const el_id_winnerPlayAgain = document.querySelector("#winnerPlayAgain");
|
|
|
|
|
|
|
|
|
|
function endGame() {
|
|
|
|
|
goToState("winner");
|
|
|
|
|
el_id_game.hidden = true;
|
|
|
|
|
el_id_winner.hidden = false;
|
|
|
|
|
const winningPlayer = state[curDepth][curFight][0];
|
|
|
|
|
el_id_winnerUserImage.src = winningPlayer.avatar;
|
|
|
|
|
el_id_winnerUserName.innerHTML = `<a href="${winningPlayer.url}" target="_blank">${renderNameHTML(escapeHtml(winningPlayer.display_name), winningPlayer)}</a>`;
|
|
|
|
|
el_id_winnerUserName.innerHTML = renderNameHTML(escapeHtml(winningPlayer.display_name), winningPlayer);
|
|
|
|
|
el_id_winnerUserId.innerHTML = "@" + winningPlayer.fqn;
|
|
|
|
|
// el_id_winnerUserNote.innerHTML = escapeHtml(winningPlayer.note);
|
|
|
|
|
// el_id_winnerUserFields.innerHTML = winningPlayer.fields.reduce((pv, fields) => pv + `<tr><td>${escapeHtml(fields.name)}</td><td>${escapeHtml(fields.value)}</td></tr>`, "");
|
|
|
|
|
el_id_winnerUserNote.innerHTML = escapeHtml(winningPlayer.note);
|
|
|
|
|
el_id_winnerUserFields.innerHTML = winningPlayer.fields.reduce((pv, fields) => pv + `<tr><td>${escapeHtml(fields.name)}</td><td>${escapeHtml(fields.value)}</td></tr>`, "");
|
|
|
|
|
|
|
|
|
|
el_id_winnermessage.innerHTML = `Congratulations, ${renderNameHTML(escapeHtml(winningPlayer.display_name), winningPlayer)}! You won the bracket!`;
|
|
|
|
|
el_id_winnerusers.innerHTML = state.reduce((pv, cs) => {
|
|
|
|
|
el_id_winnerusers.innerHTML = `<div>${state.reduce((pv, cs) => {
|
|
|
|
|
return pv + `<div class="flexUser">${cs.reduce((pvus, cus) => {
|
|
|
|
|
console.log(cus);
|
|
|
|
|
return pvus + `<div class="flexUserGroup"><div class="flexUserUser">
|
|
|
|
|
<img src="${cus[0].avatar}" width="64" height="64" />
|
|
|
|
|
<h3><a href="${cus[0].url}" target="_blank">${renderNameHTML(escapeHtml(cus[0].display_name), cus[0])}</a></h3>
|
|
|
|
|
<p>@${cus[0].fqn}</p>
|
|
|
|
|
</div>${cus[1] ? `<div class="flexUserUser">
|
|
|
|
|
<img src="${cus[1].avatar}" width="64" height="64" />
|
|
|
|
|
<h3><a href="${cus[1].url}" target="_blank">${renderNameHTML(escapeHtml(cus[1].display_name), cus[1])}</a></h3>
|
|
|
|
|
<p>@${cus[1].fqn}</p>
|
|
|
|
|
</div>` : ""}</div>`
|
|
|
|
|
return pvus + cus.reduce((pvu, cu) => {
|
|
|
|
|
return pvu + `<div class="flexUserUser">
|
|
|
|
|
<img src="${cu.avatar}" width="64" height="64" />
|
|
|
|
|
<h3>${renderNameHTML(escapeHtml(cu.display_name), cu)}</h3>
|
|
|
|
|
<p>@${cu.fqn}</p>
|
|
|
|
|
</div>`
|
|
|
|
|
}, "")
|
|
|
|
|
}, "")}</div>`
|
|
|
|
|
}, "");
|
|
|
|
|
}, "")}</div>`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
el_id_winnerPlayAgain.addEventListener("click", (x) => {
|
|
|
|
|
el_id_winner.hidden = true;
|
|
|
|
|
state = [];
|
|
|
|
|
selectedUsers = [];
|
|
|
|
|
curDepth = 0;
|
|
|
|
|
curFight = 0;
|
|
|
|
|
switch (gamemodeFollowers) {
|
|
|
|
|
case "followers":
|
|
|
|
|
startFollowers(false);
|
|
|
|
|
break;
|
|
|
|
|
case "following":
|
|
|
|
|
startFollowing(false);
|
|
|
|
|
break;
|
|
|
|
|
case "manual":
|
|
|
|
|
startManual(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Game state
|
|
|
|
|
|
|
|
|
|
const gameStates = new Map([
|
|
|
|
|
["whoami", {
|
|
|
|
|
state: el_id_whoami
|
|
|
|
|
}],
|
|
|
|
|
["followers", {
|
|
|
|
|
state: el_id_followers
|
|
|
|
|
}],
|
|
|
|
|
["following", {
|
|
|
|
|
state: el_id_following
|
|
|
|
|
}],
|
|
|
|
|
["manual", {
|
|
|
|
|
state: el_id_manual
|
|
|
|
|
}],
|
|
|
|
|
["game", {
|
|
|
|
|
state: el_id_game,
|
|
|
|
|
links: {
|
|
|
|
|
"winner": () => gamemodeFollowers
|
|
|
|
|
}
|
|
|
|
|
}],
|
|
|
|
|
["winner", {
|
|
|
|
|
state: el_id_winner
|
|
|
|
|
}]
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
let prevState = "";
|
|
|
|
|
function goToState(state) {
|
|
|
|
|
window.location.hash = state;
|
|
|
|
|
const curState = gameStates.get(state);
|
|
|
|
|
if (curState.links != null)
|
|
|
|
|
if (curState.links[prevState])
|
|
|
|
|
return goToState(curState.links[prevState]());
|
|
|
|
|
gameStates.forEach(x => x.state.hidden = true);
|
|
|
|
|
curState.state.hidden = false;
|
|
|
|
|
prevState = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goToState("whoami");
|
|
|
|
|
|
|
|
|
|
addEventListener("popstate", () => goToState(window.location.hash.slice(1)));
|
|
|
|
|
if (gamemodeFollowers)
|
|
|
|
|
getFollowers(true);
|
|
|
|
|
else
|
|
|
|
|
getFollowing(true);
|
|
|
|
|
})
|