Fixed issues with manual skipping

This commit is contained in:
Ajay Ramachandran 2020-04-04 23:26:34 -04:00
parent 2a432490bc
commit 55e17ceb60
3 changed files with 30 additions and 18 deletions

View file

@ -32,7 +32,10 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
constructor(props: NoticeProps) {
super(props);
let maxCountdownTime = props.maxCountdownTime || (() => 4);
let maxCountdownTime = () => {
if (this.props.maxCountdownTime) return this.props.maxCountdownTime();
else return 4;
};
//the id for the setInterval running the countdown
this.countdownInterval = null;

View file

@ -2,9 +2,13 @@ import * as React from "react";
import Config from "../config"
import { ContentContainer } from "../types";
import Utils from "../utils";
var utils = new Utils();
import NoticeComponent from "./NoticeComponent";
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
export interface SkipNoticeProps {
UUID: string;
autoSkip: boolean;
@ -79,6 +83,10 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
unskipText: chrome.i18n.getMessage("unskip"),
unskipCallback: this.unskip.bind(this)
}
if (!this.autoSkip) {
Object.assign(this.state, this.getUnskippedModeInfo(chrome.i18n.getMessage("skip")));
}
}
componentDidMount() {
@ -151,7 +159,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
</button>
</td>
{/* Never show button if manualSkip is disabled */}
{/* Never show button if autoSkip is enabled */}
{!this.autoSkip ? "" :
<td className="sponsorSkipNoticeRightSection">
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
@ -198,29 +206,31 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
}
/** Sets up notice to be not skipped yet */
unskippedMode(buttonText) {
//setup new callback
this.setState({
unskipText: buttonText,
unskipCallback: this.reskip.bind(this)
unskippedMode(buttonText: string) {
//setup new callback and reset countdown
this.setState(this.getUnskippedModeInfo(buttonText), () => {
this.noticeRef.current.resetCountdown();
});
}
getUnskippedModeInfo(buttonText: string) {
let maxCountdownTime = function() {
let sponsorTime = this.contentContainer().sponsorTimes[this.contentContainer().UUIDs.indexOf(this.UUID)];
let duration = Math.round(sponsorTime[1] - this.contentContainer().v.currentTime);
let sponsorTime = utils.getSponsorTimeFromUUID(this.contentContainer().sponsorTimes, this.UUID);
let duration = Math.round((sponsorTime.segment[1] - this.contentContainer().v.currentTime) * (1 / this.contentContainer().v.playbackRate));
return Math.max(duration, 4);
}.bind(this);
//reset countdown
this.setState({
return {
unskipText: buttonText,
unskipCallback: this.reskip.bind(this),
//change max duration to however much of the sponsor is left
maxCountdownTime: maxCountdownTime,
countdownTime: maxCountdownTime()
}, () => {
this.noticeRef.current.resetCountdown();
});
}
}
reskip() {

View file

@ -956,7 +956,6 @@ function previewTime(time: number) {
//skip from the start time to the end time for a certain index sponsor time
function skipToTime(v: HTMLVideoElement, index: number, sponsorTimes: SponsorTime[], openNotice: boolean) {
let autoSkip: boolean = utils.getCategorySelection(sponsorTimes[index].category).option === CategorySkipOption.AutoSkip;
if (autoSkip || previewResetter !== null) {
@ -970,7 +969,7 @@ function skipToTime(v: HTMLVideoElement, index: number, sponsorTimes: SponsorTim
if (openNotice) {
//send out the message saying that a sponsor message was skipped
if (!Config.config.dontShowNotice) {
if (!Config.config.dontShowNotice || !autoSkip) {
let skipNotice = new SkipNotice(currentUUID, autoSkip, skipNoticeContentContainer);
//auto-upvote this sponsor
@ -995,14 +994,14 @@ function skipToTime(v: HTMLVideoElement, index: number, sponsorTimes: SponsorTim
function unskipSponsorTime(UUID) {
if (sponsorTimes != null) {
//add a tiny bit of time to make sure it is not skipped again
video.currentTime = utils.getSponsorTimeFromUUID(sponsorTimes, UUID)[0] + 0.001;
video.currentTime = utils.getSponsorTimeFromUUID(sponsorTimes, UUID).segment[0] + 0.001;
}
}
function reskipSponsorTime(UUID) {
if (sponsorTimes != null) {
//add a tiny bit of time to make sure it is not skipped again
video.currentTime = utils.getSponsorTimeFromUUID(sponsorTimes, UUID)[1];
video.currentTime = utils.getSponsorTimeFromUUID(sponsorTimes, UUID).segment[1];
}
}