aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-07-12 18:28:41 -0400
committerAjay Ramachandran <[email protected]>2019-07-12 18:28:41 -0400
commitbaa85cc7d374f0eb88707d428810c8c8c1dd947d (patch)
treef261f3976715cf57d74bdea1d3602c6bba5cb68b
parent8e783e8466abbc48d963e45aa4f12a326b24003f (diff)
downloadSponsorBlock-baa85cc7d374f0eb88707d428810c8c8c1dd947d.tar.gz
SponsorBlock-baa85cc7d374f0eb88707d428810c8c8c1dd947d.zip
Made the onvideo control start with the stop icon if needed.
-rw-r--r--background.js29
-rw-r--r--content.js27
2 files changed, 44 insertions, 12 deletions
diff --git a/background.js b/background.js
index ff3b632b..3997e50e 100644
--- a/background.js
+++ b/background.js
@@ -26,26 +26,42 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
callback({
success: true
});
- } else if(request.message == "ytvideoid") {
+ } else if (request.message == "ytvideoid") {
if (previousVideoID != request.videoID) {
videoIDChange(request.videoID);
}
- } else if(request.message == "addSponsorTime") {
+ } else if (request.message == "addSponsorTime") {
addSponsorTime(request.time);
+ } else if (request.message == "getSponsorTimes") {
+ getSponsorTimes(request.videoID, function(sponsorTimes) {
+ callback({
+ sponsorTimes: sponsorTimes
+ })
+ });
+
+ //this allows the callback to be called later
+ return true;
}
});
-function addSponsorTime(time) {
- //get sponsor times
+
+//gets the sponsor times from memory
+function getSponsorTimes(videoID, callback) {
let sponsorTimes = [];
- let sponsorTimeKey = "sponsorTimes" + previousVideoID;
+ let sponsorTimeKey = "sponsorTimes" + videoID;
chrome.storage.local.get([sponsorTimeKey], function(result) {
let sponsorTimesStorage = result[sponsorTimeKey];
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
sponsorTimes = sponsorTimesStorage;
}
- //add to sponsorTimes
+ callback(sponsorTimes)
+ });
+}
+
+function addSponsorTime(time) {
+ getSponsorTimes(previousVideoID, function(sponsorTimes) {
+ //add to sponsorTimes
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
//it is an end time
sponsorTimes[sponsorTimes.length - 1][1] = parseInt(time);
@@ -58,6 +74,7 @@ function addSponsorTime(time) {
}
//save this info
+ let sponsorTimeKey = "sponsorTimes" + previousVideoID;
chrome.storage.local.set({[sponsorTimeKey]: sponsorTimes});
});
}
diff --git a/content.js b/content.js
index 10f785e6..c7ef2575 100644
--- a/content.js
+++ b/content.js
@@ -1,7 +1,5 @@
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
- //reset sponsor data found check
- sponsorDataFound = false;
- sponsorsLookup(id);
+ videoIDChange(id);
//tell background.js about this
chrome.runtime.sendMessage({
@@ -43,9 +41,7 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
function(request, sender, sendResponse) {
//message from background script
if (request.message == "ytvideoid") {
- //reset sponsor data found check
- sponsorDataFound = false;
- sponsorsLookup(request.id);
+ videoIDChange(request.id);
}
//messages from popup script
@@ -76,6 +72,25 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
}
});
+function videoIDChange(id) {
+ //reset sponsor data found check
+ sponsorDataFound = false;
+ sponsorsLookup(id);
+
+ //see if the onvideo control image needs to be changed
+ chrome.runtime.sendMessage({
+ message: "getSponsorTimes",
+ videoID: id
+ }, function(response) {
+ if (response != undefined) {
+ let sponsorTimes = response.sponsorTimes;
+ if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
+ toggleStartSponsorButton();
+ }
+ }
+ });
+}
+
function sponsorsLookup(id) {
v = document.querySelector('video') // Youtube video player
let xmlhttp = new XMLHttpRequest();