diff --git a/public/content.css b/public/content.css index 04385c44..fb600aa4 100644 --- a/public/content.css +++ b/public/content.css @@ -313,4 +313,21 @@ .sponsorSkipDontShowButton:active { position:relative; top:1px; +} + +/* Submission Notice */ + +.sponsorTimeDisplay { + font-size: 15px; +} + +.sponsorTimeEditButton { + text-decoration: underline; + + margin-left: 20px; + margin-right: 20px; + + font-size: 13px; + + cursor: pointer; } \ No newline at end of file diff --git a/src/background.ts b/src/background.ts index d0508d2c..9fedf5fc 100644 --- a/src/background.ts +++ b/src/background.ts @@ -187,7 +187,7 @@ async function submitTimes(videoID, callback) { let userID = Config.config.userID; if (sponsorTimes != undefined && sponsorTimes.length > 0) { - let durationResult = await new Promise((resolve, reject) => { + let durationResult = await new Promise((resolve, reject) => { chrome.tabs.query({ active: true, currentWindow: true diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index e15407c1..a366af7a 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -1,5 +1,6 @@ import * as React from "react"; import Config from "../config" +import { ContentContainer } from "../types"; import NoticeComponent from "./NoticeComponent"; import NoticeTextSelectionComponent from "./NoticeTextSectionComponent"; @@ -8,7 +9,7 @@ export interface SkipNoticeProps { UUID: string; manualSkip: boolean; // Contains functions and variables from the content script needed by the skip notice - contentContainer: () => any; + contentContainer: ContentContainer; } export interface SkipNoticeState { @@ -28,7 +29,7 @@ class SkipNoticeComponent extends React.Component any; + contentContainer: ContentContainer; amountOfPreviousNotices: number; diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index 9a52896f..a958aa16 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -1,11 +1,20 @@ import * as React from "react"; +import Config from "../config" + +import Utils from "../utils"; +import { ContentContainer } from "../types"; +import SubmissionNoticeComponent from "./SubmissionNoticeComponent"; +var utils = new Utils(); + export interface SponsorTimeEditProps { index: number, idSuffix: string, // Contains functions and variables from the content script needed by the skip notice - contentContainer: () => any; + contentContainer: ContentContainer, + + submissionNotice: SubmissionNoticeComponent; } export interface SponsorTimeEditState { @@ -19,28 +28,69 @@ class SponsorTimeEditComponent extends React.Component +
- {this.props.contentContainer().sponsorTimesSubmitting[this.props.index][0] - + " to " + this.props.contentContainer().sponsorTimesSubmitting[this.props.index][1]} + className="sponsorTimeDisplay"> + {utils.getFormattedTime(this.props.contentContainer().sponsorTimesSubmitting[this.props.index][0]) + + " to " + utils.getFormattedTime(this.props.contentContainer().sponsorTimesSubmitting[this.props.index][1])}
- + {chrome.i18n.getMessage("delete")} - + {chrome.i18n.getMessage("preview")} - + {chrome.i18n.getMessage("edit")} - +
); } + + deleteTime(): void { + let sponsorTimes = this.props.contentContainer().sponsorTimesSubmitting; + let index = this.props.index; + + //if it is not a complete sponsor time + if (sponsorTimes[index].length < 2) { + //update video player + this.props.contentContainer().changeStartSponsorButton(true, false); + } + + sponsorTimes.splice(index, 1); + + //save this + Config.config.sponsorTimes.set(this.props.contentContainer().sponsorVideoID, sponsorTimes); + + this.props.contentContainer().updatePreviewBar(); + + //if they are all removed + if (sponsorTimes.length == 0) { + this.props.submissionNotice.cancel(); + + //update video player + this.props.contentContainer().changeStartSponsorButton(true, false); + } else { + //update display + this.props.submissionNotice.forceUpdate(); + } + } } export default SponsorTimeEditComponent; \ No newline at end of file diff --git a/src/components/SubmissionNoticeComponent.tsx b/src/components/SubmissionNoticeComponent.tsx index 69c57c0f..b85efce8 100644 --- a/src/components/SubmissionNoticeComponent.tsx +++ b/src/components/SubmissionNoticeComponent.tsx @@ -1,32 +1,33 @@ import * as React from "react"; import Config from "../config" +import { ContentContainer } from "../types"; import NoticeComponent from "./NoticeComponent"; import NoticeTextSelectionComponent from "./NoticeTextSectionComponent"; import SponsorTimeEditComponent from "./SponsorTimeEditComponent"; -export interface SkipNoticeProps { +export interface SubmissionNoticeProps { // Contains functions and variables from the content script needed by the skip notice - contentContainer: () => any; + contentContainer: ContentContainer; callback: () => any; } -export interface SkipNoticeState { +export interface SubmissionNoticeeState { noticeTitle: string, messages: string[], idSuffix: string; } -class SkipNoticeComponent extends React.Component { +class SubmissionNoticeComponent extends React.Component { // Contains functions and variables from the content script needed by the skip notice - contentContainer: () => any; + contentContainer: ContentContainer; callback: () => any; noticeRef: React.MutableRefObject; - constructor(props: SkipNoticeProps) { + constructor(props: SubmissionNoticeProps) { super(props); this.noticeRef = React.createRef(); @@ -101,7 +102,8 @@ class SkipNoticeComponent extends React.Component + contentContainer={this.props.contentContainer} + submissionNotice={this}> ) } @@ -118,7 +120,7 @@ class SkipNoticeComponent extends React.Component - ) + ); } return elements; @@ -135,7 +137,6 @@ class SkipNoticeComponent extends React.Component ({ +var skipNoticeContentContainer: ContentContainer = () => ({ vote, dontShowNoticeAgain, unskipSponsorTime, sponsorTimes, sponsorTimesSubmitting, + hiddenSponsorTimes, UUIDs, v: video, + sponsorVideoID, reskipSponsorTime, - hiddenSponsorTimes, updatePreviewBar, onMobileYouTube, sponsorSubmissionNotice: submissionNotice, - resetSponsorSubmissionNotice + resetSponsorSubmissionNotice, + changeStartSponsorButton }); //get messages from the background script and the popup @@ -1136,8 +1140,8 @@ function clearSponsorTimes() { } //if skipNotice is null, it will not affect the UI -function vote(type, UUID, skipNotice: SkipNoticeComponent) { - if (skipNotice != null) { +function vote(type, UUID, skipNotice?: SkipNoticeComponent) { + if (skipNotice !== null && skipNotice !== undefined) { //add loading info skipNotice.addVoteButtonInfo.bind(skipNotice)("Loading...") skipNotice.setNoticeInfoMessage.bind(skipNotice)(); diff --git a/src/types.ts b/src/types.ts index 7b50adab..3ee9743a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,32 @@ -interface videoDurationResponse { +import SubmissionNotice from "./render/SubmissionNotice"; +import SkipNoticeComponent from "./components/SkipNoticeComponent"; + +interface ContentContainer { + (): { + vote: (type: any, UUID: any, skipNotice?: SkipNoticeComponent) => void, + dontShowNoticeAgain: () => void, + unskipSponsorTime: (UUID: any) => void, + sponsorTimes: number[][], + sponsorTimesSubmitting: number[][], + hiddenSponsorTimes: any[], + UUIDs: any[], + v: HTMLVideoElement, + sponsorVideoID, + reskipSponsorTime: (UUID: any) => void, + updatePreviewBar: () => void, + onMobileYouTube: boolean, + sponsorSubmissionNotice: SubmissionNotice, + resetSponsorSubmissionNotice: () => void, + changeStartSponsorButton: (showStartSponsor: any, uploadButtonVisible: any) => Promise + } +} + +interface VideoDurationResponse { duration: number; } + export { - videoDurationResponse + VideoDurationResponse, + ContentContainer }; \ No newline at end of file