mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 04:57:09 +03:00
Added what the sponsor times being submitted are to the confirmation message.
This commit is contained in:
57
content.js
57
content.js
@@ -607,13 +607,30 @@ function sponsorMessageStarted() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function submitSponsorTimes() {
|
function submitSponsorTimes() {
|
||||||
if(!confirm("Are you sure you want to submit this?")) return;
|
|
||||||
|
|
||||||
if (document.getElementById("submitButton").style.display == "none") {
|
if (document.getElementById("submitButton").style.display == "none") {
|
||||||
//don't submit, not ready
|
//don't submit, not ready
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let currentVideoID = getYouTubeVideoID(document.URL);
|
||||||
|
|
||||||
|
let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
|
||||||
|
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||||
|
let sponsorTimes = result[sponsorTimeKey];
|
||||||
|
|
||||||
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
|
let confirmMessage = "Are you sure you want to submit this?\n\n" + getSponsorTimesMessage(sponsorTimes);
|
||||||
|
if(!confirm(confirmMessage)) return;
|
||||||
|
|
||||||
|
sendSubmitMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//send the message to the background js
|
||||||
|
//called after all the checks have been made that it's okay to do so
|
||||||
|
function sendSubmitMessage(){
|
||||||
//add loading animation
|
//add loading animation
|
||||||
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
document.getElementById("submitButtonImage").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";
|
||||||
@@ -649,6 +666,42 @@ function submitSponsorTimes() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get the message that visually displays the video times
|
||||||
|
function getSponsorTimesMessage(sponsorTimes) {
|
||||||
|
let sponsorTimesMessage = "";
|
||||||
|
|
||||||
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
|
for (let s = 0; s < sponsorTimes[i].length; s++) {
|
||||||
|
let timeMessage = getFormattedTime(sponsorTimes[i][s]);
|
||||||
|
//if this is an end time
|
||||||
|
if (s == 1) {
|
||||||
|
timeMessage = " to " + timeMessage;
|
||||||
|
} else if (i > 0) {
|
||||||
|
//add commas if necessary
|
||||||
|
timeMessage = ", " + timeMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
sponsorTimesMessage += timeMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sponsorTimesMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
//converts time in seconds to minutes:seconds
|
||||||
|
function getFormattedTime(seconds) {
|
||||||
|
let minutes = Math.floor(seconds / 60);
|
||||||
|
let secondsDisplay = Math.round(seconds - minutes * 60);
|
||||||
|
if (secondsDisplay < 10) {
|
||||||
|
//add a zero
|
||||||
|
secondsDisplay = "0" + secondsDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
let formatted = minutes+ ":" + secondsDisplay;
|
||||||
|
|
||||||
|
return formatted;
|
||||||
|
}
|
||||||
|
|
||||||
function sendRequestToServer(type, address, callback) {
|
function sendRequestToServer(type, address, callback) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user