Made preview button functional

This commit is contained in:
Ajay Ramachandran
2020-03-11 19:56:16 -04:00
parent 37662138df
commit f100ee4738
3 changed files with 45 additions and 3 deletions

View File

@@ -51,7 +51,8 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
</span> </span>
<span id={"sponsorTimePreviewButton" + this.props.index + this.props.idSuffix} <span id={"sponsorTimePreviewButton" + this.props.index + this.props.idSuffix}
className="sponsorTimeEditButton"> className="sponsorTimeEditButton"
onClick={this.previewTime.bind(this)}>
{chrome.i18n.getMessage("preview")} {chrome.i18n.getMessage("preview")}
</span> </span>
@@ -63,6 +64,24 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
); );
} }
previewTime(): void {
let sponsorTimes = this.props.contentContainer().sponsorTimesSubmitting;
let index = this.props.index;
let skipTime = sponsorTimes[index][0];
// if (document.getElementById("startTimeMinutes" + index) != null) {
// //edit is currently open, use that time
// skipTime = getSponsorTimeEditTimes("startTime", index);
// //save the edit
// saveSponsorTimeEdit(index, false);
// }
this.props.contentContainer().previewTime(skipTime - 2);
}
deleteTime(): void { deleteTime(): void {
let sponsorTimes = this.props.contentContainer().sponsorTimesSubmitting; let sponsorTimes = this.props.contentContainer().sponsorTimesSubmitting;
let index = this.props.index; let index = this.props.index;

View File

@@ -116,7 +116,8 @@ var skipNoticeContentContainer: ContentContainer = () => ({
onMobileYouTube, onMobileYouTube,
sponsorSubmissionNotice: submissionNotice, sponsorSubmissionNotice: submissionNotice,
resetSponsorSubmissionNotice, resetSponsorSubmissionNotice,
changeStartSponsorButton changeStartSponsorButton,
previewTime
}); });
//get messages from the background script and the popup //get messages from the background script and the popup
@@ -861,6 +862,27 @@ function getStartTimes(sponsorTimes: number[][], minimum?: number, hideHiddenSpo
return startTimes; return startTimes;
} }
/**
* Skip to exact time in a video and autoskips
*
* @param time
*/
function previewTime(time: number) {
video.currentTime = time;
// Unpause the video if needed
if (video.paused){
video.play();
}
// Start preview resetter
if (previewResetter !== null){
clearTimeout(previewResetter);
}
previewResetter = setTimeout(() => previewResetter = null, 4000);
}
//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, index, sponsorTimes, openNotice) { function skipToTime(v, index, sponsorTimes, openNotice) {
if (!Config.config.disableAutoSkip || previewResetter !== null) { if (!Config.config.disableAutoSkip || previewResetter !== null) {

View File

@@ -17,7 +17,8 @@ interface ContentContainer {
onMobileYouTube: boolean, onMobileYouTube: boolean,
sponsorSubmissionNotice: SubmissionNotice, sponsorSubmissionNotice: SubmissionNotice,
resetSponsorSubmissionNotice: () => void, resetSponsorSubmissionNotice: () => void,
changeStartSponsorButton: (showStartSponsor: any, uploadButtonVisible: any) => Promise<boolean> changeStartSponsorButton: (showStartSponsor: any, uploadButtonVisible: any) => Promise<boolean>,
previewTime: (time: number) => void
} }
} }