From 6cb07b5be3ebe3d714f89f2da73a7c6e6b22d396 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 2 Aug 2019 00:54:50 -0400 Subject: Fixed the preview sometimes not updating --- background.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'background.js') diff --git a/background.js b/background.js index cbc268b9..cbd45531 100644 --- a/background.js +++ b/background.js @@ -39,7 +39,10 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { //this allows the callback to be called later by the submitTimes function return true; } else if (request.message == "addSponsorTime") { - addSponsorTime(request.time, request.videoID); + addSponsorTime(request.time, request.videoID, callback); + + //this allows the callback to be called later + return true; } else if (request.message == "getSponsorTimes") { getSponsorTimes(request.videoID, function(sponsorTimes) { callback({ @@ -85,7 +88,7 @@ function getSponsorTimes(videoID, callback) { }); } -function addSponsorTime(time, videoID) { +function addSponsorTime(time, videoID, callback) { getSponsorTimes(videoID, function(sponsorTimes) { //add to sponsorTimes if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) { @@ -101,7 +104,7 @@ function addSponsorTime(time, videoID) { //save this info let sponsorTimeKey = "sponsorTimes" + videoID; - chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}); + chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, callback); }); } -- cgit v1.2.3