effie-tiktok-extension/extension/popup.js
2024-01-14 20:39:42 -05:00

58 lines
1.4 KiB
JavaScript

const table = document.getElementById("table");
const rowBlueprint = table.getElementsByTagName("tr")[0];
rowBlueprint.remove();
let token = "";
let maxCursor = new Date().getTime();
async function getToken() {
let msToken = "";
chrome.runtime.sendMessage(null, (response) => {
msToken = response;
});
while (!msToken) await new Promise((r) => setTimeout(r, 200));
token = msToken;
return msToken;
}
await getToken();
while (true) {
let responseText = await (
await fetch(
"https://www.tiktok.com/api/user/list/?" +
new URLSearchParams({
count: 199,
maxCursor: maxCursor,
minCursor: maxCursor - 2000000,
scene: 21,
msToken: token,
}),
)
).text();
let data = JSON.parse(responseText);
if ("userList" in data) {
for (const userData of data.userList) {
if (userData.user.relation == 2) continue;
addRow(userData.user);
}
maxCursor = data.minCursor;
} else break;
if (!data.hasMore) break;
}
function addRow(user) {
let row = rowBlueprint.cloneNode(true);
let cells = row.getElementsByTagName("td");
cells[0].getElementsByTagName("img")[0].src = user.avatarThumb;
cells[1].textContent = user.nickname;
let id = cells[2].getElementsByTagName("a")[0];
id.textContent = user.uniqueId;
id.href = "https://tiktok.com/@" + user.uniqueId;
table.appendChild(row);
}