mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
commit
137ba895bb
3 changed files with 55 additions and 35 deletions
|
@ -5,38 +5,39 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
|||
});
|
||||
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||
if (request.message == "submitTimes") {
|
||||
submitTimes(request.videoID, 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, callback);
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
} else if (request.message == "getSponsorTimes") {
|
||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||
callback({
|
||||
sponsorTimes: sponsorTimes
|
||||
})
|
||||
});
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
} else if (request.message == "submitVote") {
|
||||
submitVote(request.type, request.UUID, callback);
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
} else if (request.message == "alertPrevious") {
|
||||
chrome.notifications.create("stillThere" + Math.random(), {
|
||||
type: "basic",
|
||||
title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
|
||||
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
|
||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||
});
|
||||
}
|
||||
switch(request.message) {
|
||||
case "submitTimes":
|
||||
submitTimes(request.videoID, callback);
|
||||
|
||||
//this allows the callback to be called later by the submitTimes function
|
||||
return true;
|
||||
case "addSponsorTime":
|
||||
addSponsorTime(request.time, request.videoID, callback);
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "getSponsorTimes":
|
||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||
callback({
|
||||
sponsorTimes: sponsorTimes
|
||||
})
|
||||
});
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "submitVote":
|
||||
submitVote(request.type, request.UUID, callback);
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "alertPrevious":
|
||||
chrome.notifications.create("stillThere" + Math.random(), {
|
||||
type: "basic",
|
||||
title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
|
||||
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
|
||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//add help page on install
|
||||
|
|
23
content.js
23
content.js
|
@ -16,6 +16,8 @@ var youtubeVideoStartTime = null;
|
|||
//the video
|
||||
var v;
|
||||
|
||||
var listenerAdded;
|
||||
|
||||
//the channel this video is about
|
||||
var channelURL;
|
||||
|
||||
|
@ -241,6 +243,9 @@ function videoIDChange(id) {
|
|||
sponsorVideoID = id;
|
||||
sponsorLookupRetries = 0;
|
||||
|
||||
//empty the preview bar
|
||||
previewBar.set([], [], 0);
|
||||
|
||||
//see if there is a video start time
|
||||
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
|
||||
|
||||
|
@ -320,7 +325,14 @@ function sponsorsLookup(id) {
|
|||
|
||||
//update the preview bar
|
||||
//leave the type blank for now until categories are added
|
||||
previewBar.set(sponsorTimes, [], v.duration);
|
||||
console.log(v.duration)
|
||||
if (isNaN(v.duration)) {
|
||||
//wait until it is loaded
|
||||
v.addEventListener('durationchange', updatePreviewBar);
|
||||
} else {
|
||||
//set it now
|
||||
updatePreviewBar();
|
||||
}
|
||||
|
||||
getChannelID();
|
||||
|
||||
|
@ -342,7 +354,7 @@ function sponsorsLookup(id) {
|
|||
});
|
||||
|
||||
sponsorLookupRetries = 0;
|
||||
} else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 15) {
|
||||
} else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 90) {
|
||||
//some error occurred, try again in a second
|
||||
setTimeout(() => sponsorsLookup(id), 1000);
|
||||
|
||||
|
@ -356,6 +368,13 @@ function sponsorsLookup(id) {
|
|||
};
|
||||
}
|
||||
|
||||
function updatePreviewBar() {
|
||||
previewBar.set(sponsorTimes, [], v.duration);
|
||||
|
||||
//the listener is only needed once
|
||||
v.removeEventListener('durationchange', updatePreviewBar);
|
||||
}
|
||||
|
||||
function getChannelID() {
|
||||
//get channel id
|
||||
let channelContainers = document.querySelectorAll("#owner-name");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
||||
"short_name": "SponsorBlock",
|
||||
"version": "1.0.34",
|
||||
"version": "1.0.35",
|
||||
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||
"content_scripts": [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue