diff options
author | Ajay Ramachandran <[email protected]> | 2021-08-17 20:47:40 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2021-08-17 20:47:40 -0400 |
commit | a3c80573fab666bf1d3c5df298e71ab68443bdfe (patch) | |
tree | a7c6d414575d8f1cd05e4c69381173969da54143 | |
parent | a13f5d23593012649d24e0565579dc2b60994c86 (diff) | |
download | SponsorBlock-a3c80573fab666bf1d3c5df298e71ab68443bdfe.tar.gz SponsorBlock-a3c80573fab666bf1d3c5df298e71ab68443bdfe.zip |
Make unskip work with highlight segment
-rw-r--r-- | src/components/SkipNoticeComponent.tsx | 4 | ||||
-rw-r--r-- | src/content.ts | 34 | ||||
-rw-r--r-- | src/render/SkipNotice.tsx | 5 | ||||
-rw-r--r-- | src/types.ts | 11 |
4 files changed, 42 insertions, 12 deletions
diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 5bd92966..a11cdcc1 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -26,6 +26,8 @@ export interface SkipNoticeProps { closeListener: () => void; showKeybindHint?: boolean; smaller: boolean; + + unskipTime?: number; } export interface SkipNoticeState { @@ -455,7 +457,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta } unskip(index: number): void { - this.contentContainer().unskipSponsorTime(this.segments[index]); + this.contentContainer().unskipSponsorTime(this.segments[index], this.props.unskipTime); this.unskippedMode(index, chrome.i18n.getMessage("reskip")); } diff --git a/src/content.ts b/src/content.ts index 5e00679c..96fb35a6 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,5 +1,5 @@ import Config from "./config"; -import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, VideoInfo, StorageChangesObject, CategoryActionType, ChannelIDInfo, ChannelIDStatus, SponsorSourceType, SegmentUUID, Category } from "./types"; +import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, VideoInfo, StorageChangesObject, CategoryActionType, ChannelIDInfo, ChannelIDStatus, SponsorSourceType, SegmentUUID, Category, SkipToTimeParams } from "./types"; import { ContentContainer } from "./types"; import Utils from "./utils"; @@ -448,7 +448,12 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?: if (incorrectVideoCheck(videoID, currentSkip)) return; if (video.currentTime >= skipTime[0] && video.currentTime < skipTime[1]) { - skipToTime(video, skipTime, skippingSegments, skipInfo.openNotice); + skipToTime({ + v: video, + skipTime, + skippingSegments, + openNotice: skipInfo.openNotice + }); if (utils.getCategorySelection(currentSkip.category)?.option === CategorySkipOption.ManualSkip) { forcedSkipTime = skipTime[0] + 0.001; @@ -568,7 +573,13 @@ function setupVideoListeners() { video.currentTime - segment.segment[0] > 0 && video.currentTime - segment.segment[0] < video.duration * 0.006); // Approximate size on preview bar if (currentPoiSegment) { - skipToTime(video, currentPoiSegment.segment, [currentPoiSegment], true, true); + skipToTime({ + v: video, + skipTime: currentPoiSegment.segment, + skippingSegments: [currentPoiSegment], + openNotice: true, + forceAutoSkip: true + }); } } }); @@ -744,7 +755,13 @@ function startSkipScheduleCheckingForStartSponsors() { for (const time of poiSegments) { const skipOption = utils.getCategorySelection(time.category)?.option; if (skipOption !== CategorySkipOption.ShowOverlay) { - skipToTime(video, time.segment, [time], true); + skipToTime({ + v: video, + skipTime: time.segment, + skippingSegments: [time], + openNotice: true, + unskipTime: video.currentTime + }); if (skipOption === CategorySkipOption.AutoSkip) break; } } @@ -1049,7 +1066,7 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped: } //skip from the start time to the end time for a certain index sponsor time -function skipToTime(v: HTMLVideoElement, skipTime: number[], skippingSegments: SponsorTime[], openNotice: boolean, forceAutoSkip = false) { +function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, unskipTime}: SkipToTimeParams): void { // There will only be one submission if it is manual skip const autoSkip: boolean = forceAutoSkip || shouldAutoSkip(skippingSegments[0]); @@ -1067,7 +1084,7 @@ function skipToTime(v: HTMLVideoElement, skipTime: number[], skippingSegments: S //send out the message saying that a sponsor message was skipped if (!Config.config.dontShowNotice || !autoSkip) { skipNotices.forEach((notice) => notice.setShowKeybindHint(false)); - skipNotices.push(new SkipNotice(skippingSegments, autoSkip, skipNoticeContentContainer)); + skipNotices.push(new SkipNotice(skippingSegments, autoSkip, skipNoticeContentContainer, unskipTime)); } } @@ -1075,9 +1092,10 @@ function skipToTime(v: HTMLVideoElement, skipTime: number[], skippingSegments: S if (autoSkip) sendTelemetryAndCount(skippingSegments, skipTime[1] - skipTime[0], true); } -function unskipSponsorTime(segment: SponsorTime) { +function unskipSponsorTime(segment: SponsorTime, unskipTime: number = null) { //add a tiny bit of time to make sure it is not skipped again - video.currentTime = segment.segment[0] + 0.001; + console.log(unskipTime) + video.currentTime = unskipTime ?? segment.segment[0] + 0.001; } function reskipSponsorTime(segment: SponsorTime) { diff --git a/src/render/SkipNotice.tsx b/src/render/SkipNotice.tsx index 2fd73a8b..ae1b4f67 100644 --- a/src/render/SkipNotice.tsx +++ b/src/render/SkipNotice.tsx @@ -17,7 +17,7 @@ class SkipNotice { skipNoticeRef: React.MutableRefObject<SkipNoticeComponent>; - constructor(segments: SponsorTime[], autoSkip = false, contentContainer: ContentContainer) { + constructor(segments: SponsorTime[], autoSkip = false, contentContainer: ContentContainer, unskipTime: number = null) { this.skipNoticeRef = React.createRef(); this.segments = segments; @@ -45,7 +45,8 @@ class SkipNotice { contentContainer={contentContainer} ref={this.skipNoticeRef} closeListener={() => this.close()} - smaller={true} />, + smaller={true} + unskipTime={unskipTime} />, this.noticeElement ); } diff --git a/src/types.ts b/src/types.ts index 7f13f396..8d478a1a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,7 +6,7 @@ export interface ContentContainer { (): { vote: (type: number, UUID: SegmentUUID, category?: Category, skipNotice?: SkipNoticeComponent) => void, dontShowNoticeAgain: () => void, - unskipSponsorTime: (segment: SponsorTime) => void, + unskipSponsorTime: (segment: SponsorTime, unskipTime: number) => void, sponsorTimes: SponsorTime[], sponsorTimesSubmitting: SponsorTime[], skipNotices: SkipNotice[], @@ -185,4 +185,13 @@ export enum ChannelIDStatus { export interface ChannelIDInfo { id: string, status: ChannelIDStatus +} + +export interface SkipToTimeParams { + v: HTMLVideoElement, + skipTime: number[], + skippingSegments: SponsorTime[], + openNotice: boolean, + forceAutoSkip?: boolean, + unskipTime?: number }
\ No newline at end of file |