mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 12:37:05 +03:00
Added submissions with the new API
This commit is contained in:
111
src/content.ts
111
src/content.ts
@@ -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,48 +1577,93 @@ function sendSubmitMessage(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.runtime.sendMessage({
|
if (Config.config.testingServer) {
|
||||||
message: "submitTimes",
|
let response = await utils.requestToServer("POST", "/api/skipSegments", {
|
||||||
videoID: sponsorVideoID
|
videoID: sponsorVideoID,
|
||||||
}, function(response) {
|
userID: Config.config.userID,
|
||||||
if (response != undefined) {
|
segments: sponsorTimesSubmitting
|
||||||
if (response.statusCode == 200) {
|
});
|
||||||
//hide loading message
|
|
||||||
let submitButton = document.getElementById("submitButton");
|
|
||||||
//finish this animation
|
|
||||||
submitButton.style.animation = "rotate 1s";
|
|
||||||
//when the animation is over, hide the button
|
|
||||||
let animationEndListener = function() {
|
|
||||||
changeStartSponsorButton(true, false);
|
|
||||||
|
|
||||||
submitButton.style.animation = "none";
|
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.removeEventListener("animationend", animationEndListener);
|
submitButton.style.animation = "none";
|
||||||
};
|
|
||||||
|
|
||||||
submitButton.addEventListener("animationend", animationEndListener);
|
submitButton.removeEventListener("animationend", animationEndListener);
|
||||||
|
};
|
||||||
|
|
||||||
//clear the sponsor times
|
submitButton.addEventListener("animationend", animationEndListener);
|
||||||
Config.config.sponsorTimes.delete(sponsorVideoID);
|
|
||||||
|
|
||||||
//add submissions to current sponsors list
|
//clear the sponsor times
|
||||||
if (sponsorTimes === null) sponsorTimes = [];
|
Config.config.sponsorTimes.delete(sponsorVideoID);
|
||||||
|
|
||||||
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
|
//add submissions to current sponsors list
|
||||||
|
if (sponsorTimes === null) sponsorTimes = [];
|
||||||
|
|
||||||
// Empty the submitting times
|
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
|
||||||
sponsorTimesSubmitting = [];
|
|
||||||
|
|
||||||
updatePreviewBar();
|
// Empty the submitting times
|
||||||
} else {
|
sponsorTimesSubmitting = [];
|
||||||
//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.statusCode) + "\n\n" + response.responseText);
|
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({
|
||||||
|
message: "submitTimes",
|
||||||
|
videoID: sponsorVideoID
|
||||||
|
}, function(response) {
|
||||||
|
if (response != undefined) {
|
||||||
|
if (response.statusCode == 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.statusCode) + "\n\n" + response.responseText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the message that visually displays the video times
|
//get the message that visually displays the video times
|
||||||
|
|||||||
Reference in New Issue
Block a user