mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
copy segments basics done
This commit is contained in:
parent
1a0ac27e49
commit
93f02877a7
3 changed files with 66 additions and 32 deletions
|
@ -4,6 +4,7 @@ import Config from "../config"
|
||||||
import { Category, ContentContainer, CategoryActionType, SponsorHideType, SponsorTime, NoticeVisbilityMode, ActionType } 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";
|
||||||
|
import SubmissionNotice from "../render/SubmissionNotice";
|
||||||
|
|
||||||
import { getCategoryActionType, getSkippingText } from "../utils/categoryUtils";
|
import { getCategoryActionType, getSkippingText } from "../utils/categoryUtils";
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ export enum SkipNoticeAction {
|
||||||
Upvote,
|
Upvote,
|
||||||
Downvote,
|
Downvote,
|
||||||
CategoryVote,
|
CategoryVote,
|
||||||
|
CopyDownvote,
|
||||||
Unskip
|
Unskip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,12 +205,20 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
{/* Report Button */}
|
{/* Report Button */}
|
||||||
<img id={"sponsorTimesDownvoteButtonsContainer" + this.idSuffix}
|
<img id={"sponsorTimesDownvoteButtonsContainer" + this.idSuffix}
|
||||||
className="sponsorSkipObject voteButton"
|
className="sponsorSkipObject voteButton"
|
||||||
|
style={{marginRight: "10px"}}
|
||||||
src={chrome.extension.getURL("icons/thumbs_down.svg")}
|
src={chrome.extension.getURL("icons/thumbs_down.svg")}
|
||||||
title={chrome.i18n.getMessage("reportButtonInfo")}
|
title={chrome.i18n.getMessage("reportButtonInfo")}
|
||||||
onClick={() => this.adjustDownvotingState(true)}>
|
onClick={() => this.adjustDownvotingState(true)}>
|
||||||
|
|
||||||
</img>
|
</img>
|
||||||
|
|
||||||
|
{/* Copy and Downvote Button */}
|
||||||
|
<img id={"sponsorTimesDownvoteButtonsContainer" + this.idSuffix}
|
||||||
|
className="sponsorSkipObject voteButton voteButtonImageCopyDownvote"
|
||||||
|
title="Copy and downvote to create your own segment and downvote."
|
||||||
|
src={chrome.extension.getURL("icons/clipboard.svg")}
|
||||||
|
onClick={() => this.prepAction(SkipNoticeAction.CopyDownvote)}>
|
||||||
|
</img>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
:
|
:
|
||||||
|
@ -340,16 +350,6 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prepAction(action: SkipNoticeAction): void {
|
|
||||||
if (this.segments.length === 1) {
|
|
||||||
this.performAction(0, action);
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
actionState: action
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getMessageBoxes(): JSX.Element[] {
|
getMessageBoxes(): JSX.Element[] {
|
||||||
if (this.state.messages.length === 0) {
|
if (this.state.messages.length === 0) {
|
||||||
// Add a spacer if there is no text
|
// Add a spacer if there is no text
|
||||||
|
@ -380,6 +380,19 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepAction(action: SkipNoticeAction): void {
|
||||||
|
const isDownvotingCategory = (SkipNoticeAction.CategoryVote === action);
|
||||||
|
if (this.segments.length === 1) {
|
||||||
|
this.performAction(0, action);
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
actionState: action,
|
||||||
|
downvoting: false,
|
||||||
|
choosingCategory: isDownvotingCategory
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the action from the current state
|
* Performs the action from the current state
|
||||||
*
|
*
|
||||||
|
@ -398,37 +411,29 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
case SkipNoticeAction.CategoryVote:
|
case SkipNoticeAction.CategoryVote:
|
||||||
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.CopyDownvote:
|
||||||
|
this.copyDownvote(index);
|
||||||
|
break;
|
||||||
case SkipNoticeAction.Unskip:
|
case SkipNoticeAction.Unskip:
|
||||||
this.state.skipButtonCallback(index);
|
this.state.skipButtonCallback(index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
actionState: SkipNoticeAction.None
|
actionState: SkipNoticeAction.None,
|
||||||
});
|
downvoting: false,
|
||||||
}
|
|
||||||
|
|
||||||
adjustDownvotingState(value: boolean): void {
|
|
||||||
if (!value) this.clearConfigListener();
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
downvoting: value,
|
|
||||||
choosingCategory: false
|
choosingCategory: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
clearConfigListener(): void {
|
adjustDownvotingState(value: boolean): void {
|
||||||
if (this.configListener) {
|
this.setState({
|
||||||
Config.configListeners.splice(Config.configListeners.indexOf(this.configListener), 1);
|
downvoting: value,
|
||||||
this.configListener = null;
|
choosingCategory: false,
|
||||||
}
|
actionState: SkipNoticeAction.None
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openCategoryChooser(): void {
|
openCategoryChooser(): void {
|
||||||
// Add as a config listener
|
|
||||||
this.configListener = () => this.forceUpdate();
|
|
||||||
Config.configListeners.push(this.configListener);
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
choosingCategory: true,
|
choosingCategory: true,
|
||||||
downvoting: false
|
downvoting: false
|
||||||
|
@ -531,6 +536,24 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyDownvote(index: number): void {
|
||||||
|
const sponsorVideoID = this.props.contentContainer().sponsorVideoID;
|
||||||
|
const sponsorTimesSubmitting : SponsorTime = {
|
||||||
|
segment: this.segments[index].segment,
|
||||||
|
UUID: null,
|
||||||
|
category: this.segments[index].category,
|
||||||
|
actionType: this.segments[index].actionType,
|
||||||
|
source: 2
|
||||||
|
};
|
||||||
|
let segmentTimes = Config.config.segmentTimes.get(sponsorVideoID) || [];
|
||||||
|
segmentTimes.push(sponsorTimesSubmitting);
|
||||||
|
Config.config.segmentTimes.set(sponsorVideoID, segmentTimes);
|
||||||
|
this.props.contentContainer().sponsorTimesSubmitting.push(sponsorTimesSubmitting);
|
||||||
|
this.props.contentContainer().updatePreviewBar();
|
||||||
|
this.props.contentContainer().resetSponsorSubmissionNotice();
|
||||||
|
this.props.contentContainer().updateEditButtonsOnPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
setNoticeInfoMessageWithOnClick(onClick: (event: React.MouseEvent) => unknown, ...messages: string[]): void {
|
setNoticeInfoMessageWithOnClick(onClick: (event: React.MouseEvent) => unknown, ...messages: string[]): void {
|
||||||
this.setState({
|
this.setState({
|
||||||
messages,
|
messages,
|
||||||
|
@ -557,7 +580,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
}
|
}
|
||||||
|
|
||||||
closeListener(): void {
|
closeListener(): void {
|
||||||
this.clearConfigListener();
|
//this.clearConfigListener();
|
||||||
|
|
||||||
this.props.closeListener();
|
this.props.closeListener();
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,14 @@ class SBMap<T, U> extends Map {
|
||||||
this.update();
|
this.update();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addArray(key: T, value: U) {
|
||||||
|
// Expand an array by value
|
||||||
|
let result = super.get(key).concat(value);
|
||||||
|
this.set(key, result);
|
||||||
|
this.update();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
delete(key) {
|
delete(key) {
|
||||||
const result = super.delete(key);
|
const result = super.delete(key);
|
||||||
|
|
|
@ -1682,8 +1682,11 @@ function resetSponsorSubmissionNotice() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitSponsorTimes() {
|
function submitSponsorTimes() {
|
||||||
if (submissionNotice !== null) return;
|
if (submissionNotice !== null){
|
||||||
|
submissionNotice.noticeElement.style.display = (submissionNotice.noticeElement.style.display === "none") ? null : "none";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) {
|
if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) {
|
||||||
submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage);
|
submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue