Added submissions with the new API

This commit is contained in:
Ajay Ramachandran
2020-04-09 01:35:23 -04:00
parent cd03218940
commit b7870cbd74

View File

@@ -1550,7 +1550,7 @@ function submitSponsorTimes() {
//send the message to the background js //send the message to the background js
//called after all the checks have been made that it's okay to do so //called after all the checks have been made that it's okay to do so
function sendSubmitMessage(){ async function sendSubmitMessage(){
//add loading animation //add loading animation
(<HTMLImageElement> document.getElementById("submitImage")).src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png"); (<HTMLImageElement> document.getElementById("submitImage")).src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite"; document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
@@ -1577,6 +1577,50 @@ function sendSubmitMessage(){
} }
} }
if (Config.config.testingServer) {
let response = await utils.requestToServer("POST", "/api/skipSegments", {
videoID: sponsorVideoID,
userID: Config.config.userID,
segments: sponsorTimesSubmitting
});
if (response.status === 200) {
//hide loading message
let submitButton = document.getElementById("submitButton");
submitButton.style.animation = "rotate 1s";
//finish this animation
//when the animation is over, hide the button
let animationEndListener = function() {
changeStartSponsorButton(true, false);
submitButton.style.animation = "none";
submitButton.removeEventListener("animationend", animationEndListener);
};
submitButton.addEventListener("animationend", animationEndListener);
//clear the sponsor times
Config.config.sponsorTimes.delete(sponsorVideoID);
//add submissions to current sponsors list
if (sponsorTimes === null) sponsorTimes = [];
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
// Empty the submitting times
sponsorTimesSubmitting = [];
updatePreviewBar();
} else {
//show that the upload failed
document.getElementById("submitButton").style.animation = "unset";
(<HTMLImageElement> document.getElementById("submitImage")).src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
alert(utils.getErrorMessage(response.status) + "\n\n" + (await response.text()));
}
} else {
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
message: "submitTimes", message: "submitTimes",
videoID: sponsorVideoID videoID: sponsorVideoID
@@ -1585,8 +1629,8 @@ function sendSubmitMessage(){
if (response.statusCode == 200) { if (response.statusCode == 200) {
//hide loading message //hide loading message
let submitButton = document.getElementById("submitButton"); let submitButton = document.getElementById("submitButton");
//finish this animation
submitButton.style.animation = "rotate 1s"; submitButton.style.animation = "rotate 1s";
//finish this animation
//when the animation is over, hide the button //when the animation is over, hide the button
let animationEndListener = function() { let animationEndListener = function() {
changeStartSponsorButton(true, false); changeStartSponsorButton(true, false);
@@ -1620,6 +1664,7 @@ function sendSubmitMessage(){
} }
}); });
} }
}
//get the message that visually displays the video times //get the message that visually displays the video times
function getSegmentsMessage(segments: number[][]): string { function getSegmentsMessage(segments: number[][]): string {