mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-19 14:09:09 +03:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
137ba895bb | ||
|
|
ecc48de396 | ||
|
|
aa95687b56 | ||
|
|
a8147738ef | ||
|
|
4a3d36b952 | ||
|
|
f9bd82db35 | ||
|
|
c8438b9d59 | ||
|
|
44c4671977 |
@@ -5,38 +5,39 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
if (request.message == "submitTimes") {
|
switch(request.message) {
|
||||||
submitTimes(request.videoID, callback);
|
case "submitTimes":
|
||||||
|
submitTimes(request.videoID, callback);
|
||||||
//this allows the callback to be called later by the submitTimes function
|
|
||||||
return true;
|
//this allows the callback to be called later by the submitTimes function
|
||||||
} else if (request.message == "addSponsorTime") {
|
return true;
|
||||||
addSponsorTime(request.time, request.videoID, callback);
|
case "addSponsorTime":
|
||||||
|
addSponsorTime(request.time, request.videoID, callback);
|
||||||
//this allows the callback to be called later
|
|
||||||
return true;
|
//this allows the callback to be called later
|
||||||
} else if (request.message == "getSponsorTimes") {
|
return true;
|
||||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
case "getSponsorTimes":
|
||||||
callback({
|
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||||
sponsorTimes: sponsorTimes
|
callback({
|
||||||
})
|
sponsorTimes: sponsorTimes
|
||||||
});
|
})
|
||||||
|
});
|
||||||
//this allows the callback to be called later
|
|
||||||
return true;
|
//this allows the callback to be called later
|
||||||
} else if (request.message == "submitVote") {
|
return true;
|
||||||
submitVote(request.type, request.UUID, callback);
|
case "submitVote":
|
||||||
|
submitVote(request.type, request.UUID, callback);
|
||||||
//this allows the callback to be called later
|
|
||||||
return true;
|
//this allows the callback to be called later
|
||||||
} else if (request.message == "alertPrevious") {
|
return true;
|
||||||
chrome.notifications.create("stillThere" + Math.random(), {
|
case "alertPrevious":
|
||||||
type: "basic",
|
chrome.notifications.create("stillThere" + Math.random(), {
|
||||||
title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
|
type: "basic",
|
||||||
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
|
title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
|
||||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
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
|
//add help page on install
|
||||||
|
|||||||
23
content.js
23
content.js
@@ -16,6 +16,8 @@ var youtubeVideoStartTime = null;
|
|||||||
//the video
|
//the video
|
||||||
var v;
|
var v;
|
||||||
|
|
||||||
|
var listenerAdded;
|
||||||
|
|
||||||
//the channel this video is about
|
//the channel this video is about
|
||||||
var channelURL;
|
var channelURL;
|
||||||
|
|
||||||
@@ -241,6 +243,9 @@ function videoIDChange(id) {
|
|||||||
sponsorVideoID = id;
|
sponsorVideoID = id;
|
||||||
sponsorLookupRetries = 0;
|
sponsorLookupRetries = 0;
|
||||||
|
|
||||||
|
//empty the preview bar
|
||||||
|
previewBar.set([], [], 0);
|
||||||
|
|
||||||
//see if there is a video start time
|
//see if there is a video start time
|
||||||
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
|
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
|
||||||
|
|
||||||
@@ -320,7 +325,14 @@ function sponsorsLookup(id) {
|
|||||||
|
|
||||||
//update the preview bar
|
//update the preview bar
|
||||||
//leave the type blank for now until categories are added
|
//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();
|
getChannelID();
|
||||||
|
|
||||||
@@ -342,7 +354,7 @@ function sponsorsLookup(id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
sponsorLookupRetries = 0;
|
sponsorLookupRetries = 0;
|
||||||
} else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 15) {
|
} else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 90) {
|
||||||
//some error occurred, try again in a second
|
//some error occurred, try again in a second
|
||||||
setTimeout(() => sponsorsLookup(id), 1000);
|
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() {
|
function getChannelID() {
|
||||||
//get channel id
|
//get channel id
|
||||||
let channelContainers = document.querySelectorAll("#owner-name");
|
let channelContainers = document.querySelectorAll("#owner-name");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
||||||
"short_name": "SponsorBlock",
|
"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.",
|
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user