Merge pull request #15 from Ovler-Young/patch-1

Add archiveButton to enable send archive request
This commit is contained in:
yzqzss 2024-01-29 21:25:23 +08:00 committed by GitHub
commit 588df3c48a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,28 @@
}
}
async function archiveVideo() {
var bvNumber = getBVNumber();
if (BASEURL === "") {
alert("请先设置存档服务器地址");
return;
}
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;