Code
Gu_Pigeon
·
2019-10-12 16:18:26
·
个人记录
(un)follow automaton
async function follow(users, self, state = true) {
for (const user of users)
await fetch("/space/show"
+ `?uid=${user}`
+ `&myuid=${self}`
+ `&follow=${+state}`);
}
chatting automaton
async function chat(who, words) {
await fetch("/api/chat/new", {
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": document.querySelector("meta[name=csrf-token]").content
},
body: JSON.stringify({
user: who,
content: words
}),
method: "POST"
});
}
blog comment automaton
async function comment(blogid, words) {
fetch(`/api/blog/reply/${blogid}`, {
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": document.querySelector("meta[name=csrf-token]").content
},
body: JSON.stringify({
content: words
}),
method: "POST"
});
}
chat delete automaton
async function deleteMessages(user) {
const headers = {
"Content-Type": "application/json",
"X-CSRF-Token": document.querySelector("meta[name=csrf-token]").content
};
for (;;) {
const messages = (await fetchJSON(`/api/chat/record?user=${user}`)).messages;
if (!messages.count) break;
for (const message of messages.result) {
await fetchJSON("/api/chat/delete", {
headers,
body: JSON.stringify({
id: message.id
}),
method: "POST"
});
console.log(`deleted message #${message.id}: ${message.content}`);
}
}
console.log("done");
}