mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Made the onvideo control start with the stop icon if needed.
This commit is contained in:
parent
8e783e8466
commit
baa85cc7d3
2 changed files with 44 additions and 12 deletions
|
@ -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});
|
||||
});
|
||||
}
|
||||
|
|
27
content.js
27
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();
|
||||
|
|
Loading…
Reference in a new issue