Added duration check to popup as well.

This commit is contained in:
Ajay Ramachandran 2019-08-22 23:12:30 -04:00
parent 98eb72ef1f
commit 2fbafb6b10
2 changed files with 27 additions and 1 deletions

View file

@ -147,11 +147,29 @@ function submitVote(type, UUID, callback) {
function submitTimes(videoID, callback) {
//get the video times from storage
let sponsorTimeKey = 'sponsorTimes' + videoID;
chrome.storage.sync.get([sponsorTimeKey, "userID"], function(result) {
chrome.storage.sync.get([sponsorTimeKey, "userID"], async function(result) {
let sponsorTimes = result[sponsorTimeKey];
let userID = result.userID;
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
let durationResult = await new Promise((resolve, reject) => {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
message: "getVideoDuration"
}, (response) => resolve(response));
});
});
//check if a sponsor exceeds the duration of the video
for (let i = 0; i < sponsorTimes.length; i++) {
if (sponsorTimes[i][1] > durationResult.duration) {
sponsorTimes[i][1] = durationResult.duration;
}
}
//submit these times
for (let i = 0; i < sponsorTimes.length; i++) {
//submit the sponsorTime

View file

@ -128,6 +128,12 @@ function messageListener(request, sender, sendResponse) {
})
}
if (request.message == "getVideoDuration") {
sendResponse({
duration: v.duration
});
}
if (request.message == "skipToTime") {
v.currentTime = request.time;
}
@ -964,6 +970,8 @@ function submitSponsorTimes() {
sponsorTimes[i][1] = v.duration;
}
}
//update sponsorTimes
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes);
confirmMessage += "\n\n" + chrome.i18n.getMessage("confirmMSG");