aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--background.js20
-rw-r--r--content.js8
2 files changed, 27 insertions, 1 deletions
diff --git a/background.js b/background.js
index 64c7813c..aa25e379 100644
--- a/background.js
+++ b/background.js
@@ -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
diff --git a/content.js b/content.js
index 303b4d41..c63ef7c5 100644
--- a/content.js
+++ b/content.js
@@ -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");