mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Make unskip work with highlight segment
This commit is contained in:
parent
a13f5d2359
commit
a3c80573fa
4 changed files with 42 additions and 12 deletions
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
11
src/types.ts
11
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[],
|
||||
|
@ -186,3 +186,12 @@ export interface ChannelIDInfo {
|
|||
id: string,
|
||||
status: ChannelIDStatus
|
||||
}
|
||||
|
||||
export interface SkipToTimeParams {
|
||||
v: HTMLVideoElement,
|
||||
skipTime: number[],
|
||||
skippingSegments: SponsorTime[],
|
||||
openNotice: boolean,
|
||||
forceAutoSkip?: boolean,
|
||||
unskipTime?: number
|
||||
}
|
Loading…
Reference in a new issue