mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 05:57:07 +03:00
Removed the need for getYouTubeVideoStartTime and made it check the current video time instead.
This commit is contained in:
12
content.js
12
content.js
@@ -10,9 +10,6 @@ var sponsorVideoID = null;
|
|||||||
//these are sponsors that have been downvoted
|
//these are sponsors that have been downvoted
|
||||||
var hiddenSponsorTimes = [];
|
var hiddenSponsorTimes = [];
|
||||||
|
|
||||||
//the time this video is starting at when first played, if not zero
|
|
||||||
var youtubeVideoStartTime = null;
|
|
||||||
|
|
||||||
//the video
|
//the video
|
||||||
var v;
|
var v;
|
||||||
|
|
||||||
@@ -259,9 +256,6 @@ function videoIDChange(id) {
|
|||||||
|
|
||||||
resetValues();
|
resetValues();
|
||||||
|
|
||||||
//see if there is a video start time
|
|
||||||
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
|
|
||||||
|
|
||||||
sponsorsLookup(id);
|
sponsorsLookup(id);
|
||||||
|
|
||||||
//make sure everything is properly added
|
//make sure everything is properly added
|
||||||
@@ -468,7 +462,7 @@ function checkSponsorTime(sponsorTimes, index, openNotice) {
|
|||||||
lastTime = v.currentTime - 0.0001;
|
lastTime = v.currentTime - 0.0001;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0]) && !hiddenSponsorTimes.includes(index)) {
|
if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0], sponsorTimes[index][1]) && !hiddenSponsorTimes.includes(index)) {
|
||||||
//skip it
|
//skip it
|
||||||
skipToTime(v, index, sponsorTimes, openNotice);
|
skipToTime(v, index, sponsorTimes, openNotice);
|
||||||
|
|
||||||
@@ -479,13 +473,13 @@ function checkSponsorTime(sponsorTimes, index, openNotice) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkIfTimeToSkip(currentVideoTime, startTime) {
|
function checkIfTimeToSkip(currentVideoTime, startTime, endTime) {
|
||||||
//If the sponsor time is in between these times, skip it
|
//If the sponsor time is in between these times, skip it
|
||||||
//Checks if the last time skipped to is not too close to now, to make sure not to get too many
|
//Checks if the last time skipped to is not too close to now, to make sure not to get too many
|
||||||
// sponsor times in a row (from one troll)
|
// sponsor times in a row (from one troll)
|
||||||
//the last term makes 0 second start times possible only if the video is not setup to start at a different time from zero
|
//the last term makes 0 second start times possible only if the video is not setup to start at a different time from zero
|
||||||
return (Math.abs(currentVideoTime - startTime) < 3 && startTime >= lastTime && startTime <= currentVideoTime) ||
|
return (Math.abs(currentVideoTime - startTime) < 3 && startTime >= lastTime && startTime <= currentVideoTime) ||
|
||||||
(lastTime == -1 && startTime == 0 && youtubeVideoStartTime == null)
|
(lastTime == -1 && startTime == 0 && currentVideoTime < endTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
//skip fromt he start time to the end time for a certain index sponsor time
|
//skip fromt he start time to the end time for a certain index sponsor time
|
||||||
|
|||||||
11
utils.js
11
utils.js
@@ -24,14 +24,3 @@ function getYouTubeVideoID(url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns the start time of the video if there was one specified (ex. ?t=5s)
|
|
||||||
function getYouTubeVideoStartTime(url) {
|
|
||||||
let searchParams = new URL(url).searchParams;
|
|
||||||
let startTime = searchParams.get("t");
|
|
||||||
if (startTime == null) {
|
|
||||||
startTime = searchParams.get("time_continue");
|
|
||||||
}
|
|
||||||
|
|
||||||
return startTime;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user