mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Make skip notice buttons work with mute segments
This commit is contained in:
@@ -52,6 +52,9 @@
|
|||||||
"reskip": {
|
"reskip": {
|
||||||
"message": "Reskip"
|
"message": "Reskip"
|
||||||
},
|
},
|
||||||
|
"unmute": {
|
||||||
|
"message": "Unmute"
|
||||||
|
},
|
||||||
"paused": {
|
"paused": {
|
||||||
"message": "Paused"
|
"message": "Paused"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as CompileConfig from "../../config.json";
|
import * as CompileConfig from "../../config.json";
|
||||||
import Config from "../config"
|
import Config from "../config"
|
||||||
import { Category, ContentContainer, CategoryActionType, SponsorHideType, SponsorTime, NoticeVisbilityMode } from "../types";
|
import { Category, ContentContainer, CategoryActionType, SponsorHideType, SponsorTime, NoticeVisbilityMode, ActionType } from "../types";
|
||||||
import NoticeComponent from "./NoticeComponent";
|
import NoticeComponent from "./NoticeComponent";
|
||||||
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
||||||
|
|
||||||
@@ -39,8 +39,8 @@ export interface SkipNoticeState {
|
|||||||
maxCountdownTime?: () => number;
|
maxCountdownTime?: () => number;
|
||||||
countdownText?: string;
|
countdownText?: string;
|
||||||
|
|
||||||
unskipText?: string;
|
skipButtonText?: string;
|
||||||
unskipCallback?: (index: number) => void;
|
skipButtonCallback?: (index: number) => void;
|
||||||
|
|
||||||
downvoting?: boolean;
|
downvoting?: boolean;
|
||||||
choosingCategory?: boolean;
|
choosingCategory?: boolean;
|
||||||
@@ -110,8 +110,8 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
countdownTime: Config.config.skipNoticeDuration,
|
countdownTime: Config.config.skipNoticeDuration,
|
||||||
countdownText: null,
|
countdownText: null,
|
||||||
|
|
||||||
unskipText: chrome.i18n.getMessage("unskip"),
|
skipButtonText: this.getUnskipText(),
|
||||||
unskipCallback: (index) => this.unskip(index),
|
skipButtonCallback: (index) => this.unskip(index),
|
||||||
|
|
||||||
downvoting: false,
|
downvoting: false,
|
||||||
choosingCategory: false,
|
choosingCategory: false,
|
||||||
@@ -126,7 +126,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
|
|
||||||
if (!this.autoSkip) {
|
if (!this.autoSkip) {
|
||||||
// Assume manual skip is only skipping 1 submission
|
// Assume manual skip is only skipping 1 submission
|
||||||
Object.assign(this.state, this.getUnskippedModeInfo(0, chrome.i18n.getMessage("skip")));
|
Object.assign(this.state, this.getUnskippedModeInfo(0, this.getSkipText()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
style={{marginLeft: "4px"}}
|
style={{marginLeft: "4px"}}
|
||||||
onClick={() => this.prepAction(SkipNoticeAction.Unskip)}>
|
onClick={() => this.prepAction(SkipNoticeAction.Unskip)}>
|
||||||
|
|
||||||
{this.state.unskipText + (this.state.showKeybindHint ? " (" + Config.config.skipKeybind + ")" : "")}
|
{this.state.skipButtonText + (this.state.showKeybindHint ? " (" + Config.config.skipKeybind + ")" : "")}
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
@@ -396,7 +396,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
this.contentContainer().vote(undefined, this.segments[index].UUID, this.categoryOptionRef.current.value as Category, this)
|
this.contentContainer().vote(undefined, this.segments[index].UUID, this.categoryOptionRef.current.value as Category, this)
|
||||||
break;
|
break;
|
||||||
case SkipNoticeAction.Unskip:
|
case SkipNoticeAction.Unskip:
|
||||||
this.state.unskipCallback(index);
|
this.state.skipButtonCallback(index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,7 +456,29 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
unskip(index: number): void {
|
unskip(index: number): void {
|
||||||
this.contentContainer().unskipSponsorTime(this.segments[index], this.props.unskipTime);
|
this.contentContainer().unskipSponsorTime(this.segments[index], this.props.unskipTime);
|
||||||
|
|
||||||
this.unskippedMode(index, chrome.i18n.getMessage("reskip"));
|
this.unskippedMode(index, this.getReskipText());
|
||||||
|
}
|
||||||
|
|
||||||
|
reskip(index: number): void {
|
||||||
|
this.contentContainer().reskipSponsorTime(this.segments[index]);
|
||||||
|
|
||||||
|
const newState: SkipNoticeState = {
|
||||||
|
skipButtonText: this.getUnskipText(),
|
||||||
|
skipButtonCallback: this.unskip.bind(this),
|
||||||
|
|
||||||
|
maxCountdownTime: () => Config.config.skipNoticeDuration,
|
||||||
|
countdownTime: Config.config.skipNoticeDuration
|
||||||
|
};
|
||||||
|
|
||||||
|
// See if the title should be changed
|
||||||
|
if (!this.autoSkip) {
|
||||||
|
newState.noticeTitle = chrome.i18n.getMessage("noticeTitle");
|
||||||
|
}
|
||||||
|
|
||||||
|
//reset countdown
|
||||||
|
this.setState(newState, () => {
|
||||||
|
this.noticeRef.current.resetCountdown();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets up notice to be not skipped yet */
|
/** Sets up notice to be not skipped yet */
|
||||||
@@ -478,36 +500,14 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
} : this.state.maxCountdownTime;
|
} : this.state.maxCountdownTime;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
unskipText: buttonText,
|
skipButtonText: buttonText,
|
||||||
unskipCallback: (index) => this.reskip(index),
|
skipButtonCallback: (index) => this.reskip(index),
|
||||||
// change max duration to however much of the sponsor is left
|
// change max duration to however much of the sponsor is left
|
||||||
maxCountdownTime: maxCountdownTime,
|
maxCountdownTime: maxCountdownTime,
|
||||||
countdownTime: maxCountdownTime()
|
countdownTime: maxCountdownTime()
|
||||||
} as SkipNoticeState;
|
} as SkipNoticeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
reskip(index: number): void {
|
|
||||||
this.contentContainer().reskipSponsorTime(this.segments[index]);
|
|
||||||
|
|
||||||
const newState: SkipNoticeState = {
|
|
||||||
unskipText: chrome.i18n.getMessage("unskip"),
|
|
||||||
unskipCallback: this.unskip.bind(this),
|
|
||||||
|
|
||||||
maxCountdownTime: () => Config.config.skipNoticeDuration,
|
|
||||||
countdownTime: Config.config.skipNoticeDuration
|
|
||||||
};
|
|
||||||
|
|
||||||
// See if the title should be changed
|
|
||||||
if (!this.autoSkip) {
|
|
||||||
newState.noticeTitle = chrome.i18n.getMessage("noticeTitle");
|
|
||||||
}
|
|
||||||
|
|
||||||
//reset countdown
|
|
||||||
this.setState(newState, () => {
|
|
||||||
this.noticeRef.current.resetCountdown();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
afterVote(segment: SponsorTime, type: number, category: Category): void {
|
afterVote(segment: SponsorTime, type: number, category: Category): void {
|
||||||
this.addVoteButtonInfo(chrome.i18n.getMessage("voted"));
|
this.addVoteButtonInfo(chrome.i18n.getMessage("voted"));
|
||||||
|
|
||||||
@@ -558,6 +558,42 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
|
|
||||||
this.props.closeListener();
|
this.props.closeListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getUnskipText(): string {
|
||||||
|
switch (this.props.segments[0].actionType) {
|
||||||
|
case ActionType.Mute: {
|
||||||
|
return chrome.i18n.getMessage("unmute");
|
||||||
|
}
|
||||||
|
case ActionType.Skip:
|
||||||
|
default: {
|
||||||
|
return chrome.i18n.getMessage("unskip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getReskipText(): string {
|
||||||
|
switch (this.props.segments[0].actionType) {
|
||||||
|
case ActionType.Mute: {
|
||||||
|
return chrome.i18n.getMessage("mute");
|
||||||
|
}
|
||||||
|
case ActionType.Skip:
|
||||||
|
default: {
|
||||||
|
return chrome.i18n.getMessage("reskip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getSkipText(): string {
|
||||||
|
switch (this.props.segments[0].actionType) {
|
||||||
|
case ActionType.Mute: {
|
||||||
|
return chrome.i18n.getMessage("mute");
|
||||||
|
}
|
||||||
|
case ActionType.Skip:
|
||||||
|
default: {
|
||||||
|
return chrome.i18n.getMessage("skip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SkipNoticeComponent;
|
export default SkipNoticeComponent;
|
||||||
|
|||||||
@@ -1190,19 +1190,29 @@ function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
function unskipSponsorTime(segment: SponsorTime, unskipTime: number = null) {
|
function unskipSponsorTime(segment: SponsorTime, unskipTime: number = null) {
|
||||||
//add a tiny bit of time to make sure it is not skipped again
|
if (segment.actionType === ActionType.Mute) {
|
||||||
console.log(unskipTime)
|
video.muted = false;
|
||||||
video.currentTime = unskipTime ?? segment.segment[0] + 0.001;
|
videoMuted = false;
|
||||||
|
} else {
|
||||||
|
//add a tiny bit of time to make sure it is not skipped again
|
||||||
|
video.currentTime = unskipTime ?? segment.segment[0] + 0.001;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function reskipSponsorTime(segment: SponsorTime) {
|
function reskipSponsorTime(segment: SponsorTime) {
|
||||||
const skippedTime = Math.max(segment.segment[1] - video.currentTime, 0);
|
if (segment.actionType === ActionType.Mute) {
|
||||||
const segmentDuration = segment.segment[1] - segment.segment[0];
|
video.muted = true;
|
||||||
const fullSkip = skippedTime / segmentDuration > manualSkipPercentCount;
|
videoMuted = true;
|
||||||
|
} else {
|
||||||
video.currentTime = segment.segment[1];
|
const skippedTime = Math.max(segment.segment[1] - video.currentTime, 0);
|
||||||
sendTelemetryAndCount([segment], skippedTime, fullSkip);
|
const segmentDuration = segment.segment[1] - segment.segment[0];
|
||||||
startSponsorSchedule(true, segment.segment[1], false);
|
const fullSkip = skippedTime / segmentDuration > manualSkipPercentCount;
|
||||||
|
|
||||||
|
video.currentTime = segment.segment[1];
|
||||||
|
sendTelemetryAndCount([segment], skippedTime, fullSkip);
|
||||||
|
startSponsorSchedule(true, segment.segment[1], false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createButton(baseID: string, title: string, callback: () => void, imageName: string, isDraggable = false): HTMLElement {
|
function createButton(baseID: string, title: string, callback: () => void, imageName: string, isDraggable = false): HTMLElement {
|
||||||
|
|||||||
Reference in New Issue
Block a user