(un)follow automaton
JavaScript 复制 async function follow (users , self , state = true ) {
for (const user of users)
await fetch ("/space/show"
+ `?uid=${ user}`
+ `&myuid=${ self}`
+ `&follow=${ + state}` );
}
chatting automaton
JavaScript 复制 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"
});
}
JavaScript 复制 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
JavaScript 复制 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" );
}