Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add archiveButton to enable send archive request #15

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions bilibili-archive-checker.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
Loading