mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Merge pull request #283 from ajayyy/experimental
New skipping mechanism fixes
This commit is contained in:
commit
cd11618a5d
3 changed files with 30 additions and 24 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "__MSG_fullName__",
|
||||
"short_name": "__MSG_Name__",
|
||||
"version": "1.2.14",
|
||||
"version": "1.2.15",
|
||||
"default_locale": "en",
|
||||
"description": "__MSG_Description__",
|
||||
"content_scripts": [{
|
||||
|
|
|
@ -24,16 +24,19 @@
|
|||
},
|
||||
"scripts": {
|
||||
"web-run": "npm run web-run:chrome",
|
||||
"web-run:firefox": "cd dist && web-ext run --start-url https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm",
|
||||
"web-run:firefox": "cd dist && web-ext run --start-url https://addons.mozilla.org/firefox/addon/ublock-origin/",
|
||||
"web-run:chrome": "cd dist && web-ext run --start-url https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm -t chromium",
|
||||
"build": "npm run build:chrome",
|
||||
"build:chrome": "webpack --env.browser=chrome --config webpack/webpack.prod.js",
|
||||
"build:firefox": "webpack --env.browser=firefox --config webpack/webpack.prod.js",
|
||||
"build:dev": "npm run build:dev:chrome",
|
||||
"build:dev:chrome": "webpack --env.browser=chrome --config webpack/webpack.dev.js",
|
||||
"build:dev:firefox": "webpack --env.browser=firefox --config webpack/webpack.dev.js",
|
||||
"build:watch": "npm run build:watch:chrome",
|
||||
"build:watch:chrome": "webpack --env.browser=chrome --config webpack/webpack.dev.js --watch",
|
||||
"build:watch:firefox": "webpack --env.browser=firefox --config webpack/webpack.dev.js --watch",
|
||||
"dev": "npm run build && concurrently \"npm run web-run\" \"npm run build:watch\"",
|
||||
"dev:firefox": "npm run build:firefox && concurrently \"npm run web-run:firefox\" \"npm run build:watch:firefox\"",
|
||||
"dev": "npm run build:dev && concurrently \"npm run web-run\" \"npm run build:watch\"",
|
||||
"dev:firefox": "npm run build:dev:firefox && concurrently \"npm run web-run:firefox\" \"npm run build:watch:firefox\"",
|
||||
"clean": "rimraf dist",
|
||||
"test": "npx jest"
|
||||
},
|
||||
|
|
|
@ -43,8 +43,6 @@ var lastPreviewBarUpdate;
|
|||
|
||||
//whether the duration listener listening for the duration changes of the video has been setup yet
|
||||
var durationListenerSetUp = false;
|
||||
// Timestamp of the last duration change
|
||||
var lastDurationChange = 0;
|
||||
|
||||
//the channel this video is about
|
||||
var channelURL;
|
||||
|
@ -66,10 +64,7 @@ var previewResetter: NodeJS.Timeout = null;
|
|||
var controls = null;
|
||||
|
||||
// Direct Links after the config is loaded
|
||||
utils.wait(() => Config.config !== null).then(() => videoIDChange(getYouTubeVideoID(document.URL)));
|
||||
|
||||
//the last time looked at (used to see if this time is in the interval)
|
||||
var lastTime = -1;
|
||||
utils.wait(() => Config.config !== null, 1000, 1).then(() => videoIDChange(getYouTubeVideoID(document.URL)));
|
||||
|
||||
//the amount of times the sponsor lookup has retried
|
||||
//this only happens if there is an error
|
||||
|
@ -240,9 +235,6 @@ document.onkeydown = function(e: KeyboardEvent){
|
|||
}
|
||||
|
||||
function resetValues() {
|
||||
//reset last sponsor times
|
||||
lastTime = -1;
|
||||
|
||||
//reset sponsor times
|
||||
sponsorTimes = null;
|
||||
UUIDs = [];
|
||||
|
@ -430,14 +422,14 @@ function createPreviewBar(): void {
|
|||
* This happens when the resolution changes or at random time to clear memory.
|
||||
*/
|
||||
function durationChangeListener() {
|
||||
lastDurationChange = Date.now();
|
||||
|
||||
updatePreviewBar();
|
||||
}
|
||||
|
||||
function cancelSponsorSchedule(): void {
|
||||
if (currentSkipSchedule !== null) {
|
||||
clearTimeout(currentSkipSchedule);
|
||||
|
||||
currentSkipSchedule = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -448,7 +440,7 @@ function cancelSponsorSchedule(): void {
|
|||
function startSponsorSchedule(currentTime?: number): void {
|
||||
cancelSponsorSchedule();
|
||||
|
||||
if (sponsorTimes === null || Config.config.disableSkipping || channelWhitelisted){
|
||||
if (Config.config.disableSkipping || channelWhitelisted){
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -456,18 +448,24 @@ function startSponsorSchedule(currentTime?: number): void {
|
|||
|
||||
let skipInfo = getNextSkipIndex(currentTime);
|
||||
|
||||
if (skipInfo.index === -1) return;
|
||||
|
||||
let skipTime = skipInfo.array[skipInfo.index];
|
||||
let timeUntilSponsor = skipTime[0] - currentTime;
|
||||
|
||||
currentSkipSchedule = setTimeout(() => {
|
||||
let skippingFunction = () => {
|
||||
if (video.currentTime >= skipTime[0] && video.currentTime < skipTime[1]) {
|
||||
skipToTime(video, skipInfo.index, skipInfo.array, skipInfo.openNotice);
|
||||
|
||||
startSponsorSchedule();
|
||||
} else {
|
||||
startSponsorSchedule();
|
||||
}
|
||||
}, timeUntilSponsor * 1000 * (1 / video.playbackRate));
|
||||
|
||||
startSponsorSchedule();
|
||||
};
|
||||
|
||||
if (timeUntilSponsor <= 0) {
|
||||
skippingFunction();
|
||||
} else {
|
||||
currentSkipSchedule = setTimeout(skippingFunction, timeUntilSponsor * 1000 * (1 / video.playbackRate));
|
||||
}
|
||||
}
|
||||
|
||||
function sponsorsLookup(id: string, channelIDPromise?) {
|
||||
|
@ -493,6 +491,8 @@ function sponsorsLookup(id: string, channelIDPromise?) {
|
|||
video.addEventListener('ratechange', () => startSponsorSchedule());
|
||||
video.addEventListener('seeking', cancelSponsorSchedule);
|
||||
video.addEventListener('pause', cancelSponsorSchedule);
|
||||
|
||||
startSponsorSchedule();
|
||||
}
|
||||
|
||||
if (channelIDPromise !== undefined) {
|
||||
|
@ -767,7 +767,8 @@ function getNextSkipIndex(currentTime: number): {array: number[][], index: numbe
|
|||
|
||||
let minPreviewSponsorTimeIndex = previewSponsorStartTimes.indexOf(Math.min(...previewSponsorStartTimesAfterCurrentTime));
|
||||
|
||||
if (minPreviewSponsorTimeIndex == -1 || sponsorStartTimes[minSponsorTimeIndex] < previewSponsorStartTimes[minPreviewSponsorTimeIndex]) {
|
||||
if ((minPreviewSponsorTimeIndex === -1 && minSponsorTimeIndex !== -1) ||
|
||||
sponsorStartTimes[minSponsorTimeIndex] < previewSponsorStartTimes[minPreviewSponsorTimeIndex]) {
|
||||
return {
|
||||
array: sponsorTimes,
|
||||
index: minSponsorTimeIndex,
|
||||
|
@ -791,6 +792,8 @@ function getNextSkipIndex(currentTime: number): {array: number[][], index: numbe
|
|||
* @param hideHiddenSponsors
|
||||
*/
|
||||
function getStartTimes(sponsorTimes: number[][], minimum?: number, hideHiddenSponsors: boolean = false): number[] {
|
||||
if (sponsorTimes === null) return [];
|
||||
|
||||
let startTimes: number[] = [];
|
||||
|
||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||
|
@ -802,7 +805,7 @@ function getStartTimes(sponsorTimes: number[][], minimum?: number, hideHiddenSpo
|
|||
return startTimes;
|
||||
}
|
||||
|
||||
//skip from fhe start time to the end time for a certain index sponsor time
|
||||
//skip from the start time to the end time for a certain index sponsor time
|
||||
function skipToTime(v, index, sponsorTimes, openNotice) {
|
||||
if (!Config.config.disableAutoSkip || previewResetter !== null) {
|
||||
v.currentTime = sponsorTimes[index][1];
|
||||
|
|
Loading…
Reference in a new issue