mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 14:37:23 +03:00
@@ -1,7 +1,7 @@
|
||||
import * as React from "react";
|
||||
import * as CompileConfig from "../../config.json";
|
||||
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 NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
||||
|
||||
@@ -39,8 +39,9 @@ export interface SkipNoticeState {
|
||||
maxCountdownTime?: () => number;
|
||||
countdownText?: string;
|
||||
|
||||
unskipText?: string;
|
||||
unskipCallback?: (index: number) => void;
|
||||
skipButtonText?: string;
|
||||
skipButtonCallback?: (index: number) => void;
|
||||
showSkipButton?: boolean;
|
||||
|
||||
downvoting?: boolean;
|
||||
choosingCategory?: boolean;
|
||||
@@ -110,8 +111,9 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
countdownTime: Config.config.skipNoticeDuration,
|
||||
countdownText: null,
|
||||
|
||||
unskipText: chrome.i18n.getMessage("unskip"),
|
||||
unskipCallback: (index) => this.unskip(index),
|
||||
skipButtonText: this.getUnskipText(),
|
||||
skipButtonCallback: (index) => this.unskip(index),
|
||||
showSkipButton: true,
|
||||
|
||||
downvoting: false,
|
||||
choosingCategory: false,
|
||||
@@ -126,7 +128,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
|
||||
if (!this.autoSkip) {
|
||||
// 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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,9 +299,9 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
}
|
||||
|
||||
getSkipButton(): JSX.Element {
|
||||
if (this.segments.length > 1
|
||||
if (this.state.showSkipButton && (this.segments.length > 1
|
||||
|| getCategoryActionType(this.segments[0].category) !== CategoryActionType.POI
|
||||
|| this.props.unskipTime) {
|
||||
|| this.props.unskipTime)) {
|
||||
return (
|
||||
<span className="sponsorSkipNoticeUnskipSection">
|
||||
<button id={"sponsorSkipUnskipButton" + this.idSuffix}
|
||||
@@ -307,7 +309,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
style={{marginLeft: "4px"}}
|
||||
onClick={() => this.prepAction(SkipNoticeAction.Unskip)}>
|
||||
|
||||
{this.state.unskipText + (this.state.showKeybindHint ? " (" + Config.config.skipKeybind + ")" : "")}
|
||||
{this.state.skipButtonText + (this.state.showKeybindHint ? " (" + Config.config.skipKeybind + ")" : "")}
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
@@ -397,7 +399,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
this.contentContainer().vote(undefined, this.segments[index].UUID, this.categoryOptionRef.current.value as Category, this)
|
||||
break;
|
||||
case SkipNoticeAction.Unskip:
|
||||
this.state.unskipCallback(index);
|
||||
this.state.skipButtonCallback(index);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -457,7 +459,29 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
unskip(index: number): void {
|
||||
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 */
|
||||
@@ -479,36 +503,14 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
} : this.state.maxCountdownTime;
|
||||
|
||||
return {
|
||||
unskipText: buttonText,
|
||||
unskipCallback: (index) => this.reskip(index),
|
||||
skipButtonText: buttonText,
|
||||
skipButtonCallback: (index) => this.reskip(index),
|
||||
// change max duration to however much of the sponsor is left
|
||||
maxCountdownTime: maxCountdownTime,
|
||||
countdownTime: maxCountdownTime()
|
||||
} 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 {
|
||||
this.addVoteButtonInfo(chrome.i18n.getMessage("voted"));
|
||||
|
||||
@@ -559,6 +561,52 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
|
||||
this.props.closeListener();
|
||||
}
|
||||
|
||||
unmutedListener(): void {
|
||||
if (this.props.segments.length === 1
|
||||
&& this.props.segments[0].actionType === ActionType.Mute
|
||||
&& this.contentContainer().v.currentTime >= this.props.segments[0].segment[1]) {
|
||||
this.setState({
|
||||
showSkipButton: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as React from "react";
|
||||
|
||||
import Config from "../config";
|
||||
import * as CompileConfig from "../../config.json";
|
||||
|
||||
import Config from "../config";
|
||||
import { ActionType, ActionTypes, Category, CategoryActionType, ContentContainer, SponsorTime } from "../types";
|
||||
import Utils from "../utils";
|
||||
import { Category, CategoryActionType, ContentContainer, SponsorTime } from "../types";
|
||||
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
|
||||
import { getCategoryActionType } from "../utils/categoryUtils";
|
||||
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
|
||||
|
||||
|
||||
const utils = new Utils();
|
||||
|
||||
export interface SponsorTimeEditProps {
|
||||
@@ -32,6 +32,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||
idSuffix: string;
|
||||
|
||||
categoryOptionRef: React.RefObject<HTMLSelectElement>;
|
||||
actionTypeOptionRef: React.RefObject<HTMLSelectElement>;
|
||||
|
||||
configUpdateListener: () => void;
|
||||
|
||||
@@ -39,6 +40,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||
super(props);
|
||||
|
||||
this.categoryOptionRef = React.createRef();
|
||||
this.actionTypeOptionRef = React.createRef();
|
||||
|
||||
this.idSuffix = this.props.idSuffix;
|
||||
|
||||
@@ -171,7 +173,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||
{/* Category */}
|
||||
<div style={{position: "relative"}}>
|
||||
<select id={"sponsorTimeCategories" + this.idSuffix}
|
||||
className="sponsorTimeCategories"
|
||||
className="sponsorTimeEditSelector sponsorTimeCategories"
|
||||
defaultValue={sponsorTime.category}
|
||||
ref={this.categoryOptionRef}
|
||||
onChange={this.categorySelectionChange.bind(this)}>
|
||||
@@ -188,6 +190,19 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{/* Action Type */}
|
||||
{getCategoryActionType(sponsorTime.category) === CategoryActionType.Skippable ? (
|
||||
<div style={{position: "relative"}}>
|
||||
<select id={"sponsorTimeActionTypes" + this.idSuffix}
|
||||
className="sponsorTimeEditSelector sponsorTimeActionTypes"
|
||||
defaultValue={sponsorTime.actionType}
|
||||
ref={this.actionTypeOptionRef}
|
||||
onChange={() => this.saveEditTimes()}>
|
||||
{this.getActionTypeOptions()}
|
||||
</select>
|
||||
</div>
|
||||
): ""}
|
||||
|
||||
<br/>
|
||||
|
||||
{/* Editing Tools */}
|
||||
@@ -269,6 +284,21 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||
this.saveEditTimes();
|
||||
}
|
||||
|
||||
getActionTypeOptions(): React.ReactElement[] {
|
||||
const elements = [];
|
||||
|
||||
for (const actionType of ActionTypes) {
|
||||
elements.push(
|
||||
<option value={actionType}
|
||||
key={actionType}>
|
||||
{chrome.i18n.getMessage(actionType)}
|
||||
</option>
|
||||
);
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
setTimeToNow(index: number): void {
|
||||
this.setTimeTo(index, this.props.contentContainer().getRealCurrentTime());
|
||||
}
|
||||
@@ -331,6 +361,8 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||
}
|
||||
|
||||
sponsorTimesSubmitting[this.props.index].category = this.categoryOptionRef.current.value as Category;
|
||||
sponsorTimesSubmitting[this.props.index].actionType =
|
||||
this.actionTypeOptionRef?.current ? this.actionTypeOptionRef.current.value as ActionType : ActionType.Skip;
|
||||
|
||||
Config.config.segmentTimes.set(this.props.contentContainer().sponsorVideoID, sponsorTimesSubmitting);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user