跳到正文

个人记录

Code

Gu_Pigeon约 3 分钟
原文
文章信息与版本

文章信息

发布
2019年10月12日
收录
2025年12月12日
更新
2026年11月9日
篇幅
约 3 分钟

版本

  1. v1当前

(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"
  });
}

blog comment automaton

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");
}
原文