From b72a32a5a7834d1e1c920d6b4716042443300f38 Mon Sep 17 00:00:00 2001 From: Ovler Date: Sat, 27 Jan 2024 15:13:40 +0800 Subject: [PATCH 1/2] Add archiveButton to enable send archive request --- bilibili-archive-checker.user.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bilibili-archive-checker.user.js b/bilibili-archive-checker.user.js index 17ec3a4..9fbc833 100644 --- a/bilibili-archive-checker.user.js +++ b/bilibili-archive-checker.user.js @@ -13,6 +13,7 @@ 'use strict'; const initialState = unsafeWindow.__INITIAL_STATE__; + const BASEURL = ""; // 运行API的地址,不包括 /archive/ 部分 function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); @@ -139,9 +140,20 @@ copyBV(); }); + var archiveButton = document.createElement("button"); + archiveButton.textContent = "Archive Video"; + archiveButton.style.marginTop = "10px"; + archiveButton.style.padding = "5px"; + archiveButton.style.margin = "auto"; + archiveButton.style.display = "block"; // initially hidden + archiveButton.addEventListener("click", function () { + archiveVideo(); + }); + popup.appendChild(text); popup.appendChild(status); popup.appendChild(copyButton); + popup.appendChild(archiveButton); document.body.appendChild(popup); } @@ -196,6 +208,24 @@ } } + async function archiveVideo() { + var bvNumber = getBVNumber(); + var url = `${BASEURL}/archive/${bvNumber}`; + console.log("Archive URL:", url); + showPopup("正在发送存档请求", "#f3d9a6"); + GM_xmlhttpRequest({ + method: "PUT", + url: url, + onload: function (response) { + if (response.status === 200) { + showPopup("存档请求已发送", "#bdf8bd"); + } else { + showPopup("存档请求失败", "#fac7c7"); + } + } + }); + } + async function main() { var url = null; From a844c680092d6ed103a299d9cde246cb429286b7 Mon Sep 17 00:00:00 2001 From: Ovler Date: Sat, 27 Jan 2024 15:24:56 +0800 Subject: [PATCH 2/2] If BASEURL === "", ask the user to add the BASEURL --- bilibili-archive-checker.user.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bilibili-archive-checker.user.js b/bilibili-archive-checker.user.js index 9fbc833..fae578a 100644 --- a/bilibili-archive-checker.user.js +++ b/bilibili-archive-checker.user.js @@ -210,6 +210,10 @@ async function archiveVideo() { var bvNumber = getBVNumber(); + if (BASEURL === "") { + alert("请先设置存档服务器地址"); + return; + } var url = `${BASEURL}/archive/${bvNumber}`; console.log("Archive URL:", url); showPopup("正在发送存档请求", "#f3d9a6");