Insert SyncButton on bilibili bangumi detail page to update progress

插入一个手动同步的按钮,以提交追番进度到服务器
This commit is contained in:
2024-04-21 23:34:23 +08:00
parent 11f1ed2875
commit ef26533127
7 changed files with 199 additions and 14 deletions
+16
View File
@@ -3,6 +3,7 @@ import type { PlasmoMessaging } from "@plasmohq/messaging";
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
// 添加手办
if (req.body.action === "submitAddForm") {
const { values } = req.body;
@@ -32,6 +33,21 @@ const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
res.send(addReq);
}
// 更新追番进度
if (req.body.action === "updateBangumiProgress") {
const { values } = req.body;
const updateRequest = await fetch(`${siteUrl}/api/bangumi/update`, {
method: "POST",
body: JSON.stringify(values),
headers: {
"paul-token-code": token,
},
}).then((res) => res.json());
res.send(updateRequest);
}
}
export default handler;