mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 20:47:11 +03:00
Make unskip work with highlight segment
This commit is contained in:
@@ -26,6 +26,8 @@ export interface SkipNoticeProps {
|
|||||||
closeListener: () => void;
|
closeListener: () => void;
|
||||||
showKeybindHint?: boolean;
|
showKeybindHint?: boolean;
|
||||||
smaller: boolean;
|
smaller: boolean;
|
||||||
|
|
||||||
|
unskipTime?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SkipNoticeState {
|
export interface SkipNoticeState {
|
||||||
@@ -455,7 +457,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
}
|
}
|
||||||
|
|
||||||
unskip(index: number): void {
|
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"));
|
this.unskippedMode(index, chrome.i18n.getMessage("reskip"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Config from "./config";
|
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 { ContentContainer } from "./types";
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
@@ -448,7 +448,12 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
|||||||
if (incorrectVideoCheck(videoID, currentSkip)) return;
|
if (incorrectVideoCheck(videoID, currentSkip)) return;
|
||||||
|
|
||||||
if (video.currentTime >= skipTime[0] && video.currentTime < skipTime[1]) {
|
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) {
|
if (utils.getCategorySelection(currentSkip.category)?.option === CategorySkipOption.ManualSkip) {
|
||||||
forcedSkipTime = skipTime[0] + 0.001;
|
forcedSkipTime = skipTime[0] + 0.001;
|
||||||
@@ -568,7 +573,13 @@ function setupVideoListeners() {
|
|||||||
video.currentTime - segment.segment[0] > 0 &&
|
video.currentTime - segment.segment[0] > 0 &&
|
||||||
video.currentTime - segment.segment[0] < video.duration * 0.006); // Approximate size on preview bar
|
video.currentTime - segment.segment[0] < video.duration * 0.006); // Approximate size on preview bar
|
||||||
if (currentPoiSegment) {
|
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) {
|
for (const time of poiSegments) {
|
||||||
const skipOption = utils.getCategorySelection(time.category)?.option;
|
const skipOption = utils.getCategorySelection(time.category)?.option;
|
||||||
if (skipOption !== CategorySkipOption.ShowOverlay) {
|
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;
|
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
|
//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
|
// There will only be one submission if it is manual skip
|
||||||
const autoSkip: boolean = forceAutoSkip || shouldAutoSkip(skippingSegments[0]);
|
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
|
//send out the message saying that a sponsor message was skipped
|
||||||
if (!Config.config.dontShowNotice || !autoSkip) {
|
if (!Config.config.dontShowNotice || !autoSkip) {
|
||||||
skipNotices.forEach((notice) => notice.setShowKeybindHint(false));
|
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);
|
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
|
//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) {
|
function reskipSponsorTime(segment: SponsorTime) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class SkipNotice {
|
|||||||
|
|
||||||
skipNoticeRef: React.MutableRefObject<SkipNoticeComponent>;
|
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.skipNoticeRef = React.createRef();
|
||||||
|
|
||||||
this.segments = segments;
|
this.segments = segments;
|
||||||
@@ -45,7 +45,8 @@ class SkipNotice {
|
|||||||
contentContainer={contentContainer}
|
contentContainer={contentContainer}
|
||||||
ref={this.skipNoticeRef}
|
ref={this.skipNoticeRef}
|
||||||
closeListener={() => this.close()}
|
closeListener={() => this.close()}
|
||||||
smaller={true} />,
|
smaller={true}
|
||||||
|
unskipTime={unskipTime} />,
|
||||||
this.noticeElement
|
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,
|
vote: (type: number, UUID: SegmentUUID, category?: Category, skipNotice?: SkipNoticeComponent) => void,
|
||||||
dontShowNoticeAgain: () => void,
|
dontShowNoticeAgain: () => void,
|
||||||
unskipSponsorTime: (segment: SponsorTime) => void,
|
unskipSponsorTime: (segment: SponsorTime, unskipTime: number) => void,
|
||||||
sponsorTimes: SponsorTime[],
|
sponsorTimes: SponsorTime[],
|
||||||
sponsorTimesSubmitting: SponsorTime[],
|
sponsorTimesSubmitting: SponsorTime[],
|
||||||
skipNotices: SkipNotice[],
|
skipNotices: SkipNotice[],
|
||||||
@@ -185,4 +185,13 @@ export enum ChannelIDStatus {
|
|||||||
export interface ChannelIDInfo {
|
export interface ChannelIDInfo {
|
||||||
id: string,
|
id: string,
|
||||||
status: ChannelIDStatus
|
status: ChannelIDStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SkipToTimeParams {
|
||||||
|
v: HTMLVideoElement,
|
||||||
|
skipTime: number[],
|
||||||
|
skippingSegments: SponsorTime[],
|
||||||
|
openNotice: boolean,
|
||||||
|
forceAutoSkip?: boolean,
|
||||||
|
unskipTime?: number
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user