mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 01:01:55 +01:00
Fixed issues with manual skipping
This commit is contained in:
parent
2a432490bc
commit
55e17ceb60
3 changed files with 30 additions and 18 deletions
|
@ -32,7 +32,10 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
|
||||||
constructor(props: NoticeProps) {
|
constructor(props: NoticeProps) {
|
||||||
super(props);
|
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
|
//the id for the setInterval running the countdown
|
||||||
this.countdownInterval = null;
|
this.countdownInterval = null;
|
||||||
|
|
|
@ -2,9 +2,13 @@ import * as React from "react";
|
||||||
import Config from "../config"
|
import Config from "../config"
|
||||||
import { ContentContainer } from "../types";
|
import { ContentContainer } from "../types";
|
||||||
|
|
||||||
|
import Utils from "../utils";
|
||||||
|
var utils = new Utils();
|
||||||
|
|
||||||
import NoticeComponent from "./NoticeComponent";
|
import NoticeComponent from "./NoticeComponent";
|
||||||
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
||||||
|
|
||||||
|
|
||||||
export interface SkipNoticeProps {
|
export interface SkipNoticeProps {
|
||||||
UUID: string;
|
UUID: string;
|
||||||
autoSkip: boolean;
|
autoSkip: boolean;
|
||||||
|
@ -79,6 +83,10 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
unskipText: chrome.i18n.getMessage("unskip"),
|
unskipText: chrome.i18n.getMessage("unskip"),
|
||||||
unskipCallback: this.unskip.bind(this)
|
unskipCallback: this.unskip.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.autoSkip) {
|
||||||
|
Object.assign(this.state, this.getUnskippedModeInfo(chrome.i18n.getMessage("skip")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -151,7 +159,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
{/* Never show button if manualSkip is disabled */}
|
{/* Never show button if autoSkip is enabled */}
|
||||||
{!this.autoSkip ? "" :
|
{!this.autoSkip ? "" :
|
||||||
<td className="sponsorSkipNoticeRightSection">
|
<td className="sponsorSkipNoticeRightSection">
|
||||||
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
|
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
|
||||||
|
@ -198,29 +206,31 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets up notice to be not skipped yet */
|
/** Sets up notice to be not skipped yet */
|
||||||
unskippedMode(buttonText) {
|
unskippedMode(buttonText: string) {
|
||||||
//setup new callback
|
//setup new callback and reset countdown
|
||||||
this.setState({
|
this.setState(this.getUnskippedModeInfo(buttonText), () => {
|
||||||
unskipText: buttonText,
|
this.noticeRef.current.resetCountdown();
|
||||||
unskipCallback: this.reskip.bind(this)
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getUnskippedModeInfo(buttonText: string) {
|
||||||
let maxCountdownTime = function() {
|
let maxCountdownTime = function() {
|
||||||
let sponsorTime = this.contentContainer().sponsorTimes[this.contentContainer().UUIDs.indexOf(this.UUID)];
|
let sponsorTime = utils.getSponsorTimeFromUUID(this.contentContainer().sponsorTimes, this.UUID);
|
||||||
let duration = Math.round(sponsorTime[1] - this.contentContainer().v.currentTime);
|
let duration = Math.round((sponsorTime.segment[1] - this.contentContainer().v.currentTime) * (1 / this.contentContainer().v.playbackRate));
|
||||||
|
|
||||||
return Math.max(duration, 4);
|
return Math.max(duration, 4);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
//reset countdown
|
return {
|
||||||
this.setState({
|
unskipText: buttonText,
|
||||||
|
|
||||||
|
unskipCallback: this.reskip.bind(this),
|
||||||
|
|
||||||
//change max duration to however much of the sponsor is left
|
//change max duration to however much of the sponsor is left
|
||||||
maxCountdownTime: maxCountdownTime,
|
maxCountdownTime: maxCountdownTime,
|
||||||
|
|
||||||
countdownTime: maxCountdownTime()
|
countdownTime: maxCountdownTime()
|
||||||
}, () => {
|
}
|
||||||
this.noticeRef.current.resetCountdown();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reskip() {
|
reskip() {
|
||||||
|
|
|
@ -956,7 +956,6 @@ function previewTime(time: number) {
|
||||||
|
|
||||||
//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: HTMLVideoElement, index: number, sponsorTimes: SponsorTime[], openNotice: boolean) {
|
function skipToTime(v: HTMLVideoElement, index: number, sponsorTimes: SponsorTime[], openNotice: boolean) {
|
||||||
|
|
||||||
let autoSkip: boolean = utils.getCategorySelection(sponsorTimes[index].category).option === CategorySkipOption.AutoSkip;
|
let autoSkip: boolean = utils.getCategorySelection(sponsorTimes[index].category).option === CategorySkipOption.AutoSkip;
|
||||||
|
|
||||||
if (autoSkip || previewResetter !== null) {
|
if (autoSkip || previewResetter !== null) {
|
||||||
|
@ -970,7 +969,7 @@ function skipToTime(v: HTMLVideoElement, index: number, sponsorTimes: SponsorTim
|
||||||
|
|
||||||
if (openNotice) {
|
if (openNotice) {
|
||||||
//send out the message saying that a sponsor message was skipped
|
//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);
|
let skipNotice = new SkipNotice(currentUUID, autoSkip, skipNoticeContentContainer);
|
||||||
|
|
||||||
//auto-upvote this sponsor
|
//auto-upvote this sponsor
|
||||||
|
@ -995,14 +994,14 @@ function skipToTime(v: HTMLVideoElement, index: number, sponsorTimes: SponsorTim
|
||||||
function unskipSponsorTime(UUID) {
|
function unskipSponsorTime(UUID) {
|
||||||
if (sponsorTimes != null) {
|
if (sponsorTimes != null) {
|
||||||
//add a tiny bit of time to make sure it is not skipped again
|
//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) {
|
function reskipSponsorTime(UUID) {
|
||||||
if (sponsorTimes != null) {
|
if (sponsorTimes != null) {
|
||||||
//add a tiny bit of time to make sure it is not skipped again
|
//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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue