From 9b370af340118956a89209e2cce832393c5c4dc4 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 9 Jul 2019 17:03:44 -0400 Subject: [PATCH] Fixed sponsor data found check --- content.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/content.js b/content.js index 0fbc3db2..859455d6 100644 --- a/content.js +++ b/content.js @@ -1,4 +1,6 @@ if(id = getYouTubeVideoID(document.URL)){ // Direct Links + //reset sponsor data found check + sponsorDataFound = false; sponsorsLookup(id); } @@ -13,8 +15,11 @@ var lastTime; chrome.runtime.onMessage.addListener( // Detect URL Changes function(request, sender, sendResponse) { - if (request.message === 'ytvideoid') { // Message from background script - sponsorsLookup(request.id); + //message from background script + if (request.message === 'ytvideoid') { + //reset sponsor data found check + sponsorDataFound = false; + sponsorsLookup(request.id); } //messages from popup script @@ -44,12 +49,14 @@ function sponsorsLookup(id) { xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes; + sponsorDataFound = true; - // If the sponsor data exists, add the event to run on the videos "ontimeupdate" - v.ontimeupdate = function () { - sponsorCheck(sponsorTimes); - }; + sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes; + + // If the sponsor data exists, add the event to run on the videos "ontimeupdate" + v.ontimeupdate = function () { + sponsorCheck(sponsorTimes); + }; } else { sponsorDataFound = false; }