mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 20:47:11 +03:00
Made countdown timer better support video playback speeds
This commit is contained in:
@@ -8,6 +8,8 @@ export interface NoticeProps {
|
|||||||
timed?: boolean,
|
timed?: boolean,
|
||||||
idSuffix?: string,
|
idSuffix?: string,
|
||||||
|
|
||||||
|
videoSpeed?: () => number,
|
||||||
|
|
||||||
fadeIn?: boolean,
|
fadeIn?: boolean,
|
||||||
|
|
||||||
// Callback for when this is closed
|
// Callback for when this is closed
|
||||||
@@ -19,7 +21,7 @@ export interface NoticeProps {
|
|||||||
export interface NoticeState {
|
export interface NoticeState {
|
||||||
noticeTitle: string,
|
noticeTitle: string,
|
||||||
|
|
||||||
maxCountdownTime?: () => number,
|
maxCountdownTime: () => number,
|
||||||
|
|
||||||
countdownTime: number,
|
countdownTime: number,
|
||||||
countdownText: string,
|
countdownText: string,
|
||||||
@@ -28,6 +30,8 @@ export interface NoticeState {
|
|||||||
|
|
||||||
class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
|
class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
|
||||||
countdownInterval: NodeJS.Timeout;
|
countdownInterval: NodeJS.Timeout;
|
||||||
|
intervalVideoSpeed: number;
|
||||||
|
|
||||||
idSuffix: string;
|
idSuffix: string;
|
||||||
|
|
||||||
amountOfPreviousNotices: number;
|
amountOfPreviousNotices: number;
|
||||||
@@ -154,7 +158,11 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
|
|||||||
countdown(): void {
|
countdown(): void {
|
||||||
if (!this.props.timed) return;
|
if (!this.props.timed) return;
|
||||||
|
|
||||||
const countdownTime = this.state.countdownTime - 1;
|
const countdownTime = Math.min(this.state.countdownTime - 1, this.state.maxCountdownTime());
|
||||||
|
|
||||||
|
if (this.props.videoSpeed && this.intervalVideoSpeed != this.props.videoSpeed()) {
|
||||||
|
this.setupInterval();
|
||||||
|
}
|
||||||
|
|
||||||
if (countdownTime <= 0) {
|
if (countdownTime <= 0) {
|
||||||
//remove this from setInterval
|
//remove this from setInterval
|
||||||
@@ -217,7 +225,11 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
|
|||||||
|
|
||||||
setupInterval(): void {
|
setupInterval(): void {
|
||||||
if (this.countdownInterval) clearInterval(this.countdownInterval);
|
if (this.countdownInterval) clearInterval(this.countdownInterval);
|
||||||
this.countdownInterval = setInterval(this.countdown.bind(this), 1000);
|
|
||||||
|
const intervalDuration = this.props.videoSpeed ? 1000 / this.props.videoSpeed() : 1000;
|
||||||
|
this.countdownInterval = setInterval(this.countdown.bind(this), intervalDuration);
|
||||||
|
|
||||||
|
if (this.props.videoSpeed) this.intervalVideoSpeed = this.props.videoSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
resetCountdown(): void {
|
resetCountdown(): void {
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
fadeIn={true}
|
fadeIn={true}
|
||||||
timed={true}
|
timed={true}
|
||||||
maxCountdownTime={this.state.maxCountdownTime}
|
maxCountdownTime={this.state.maxCountdownTime}
|
||||||
|
videoSpeed={() => this.contentContainer().v?.playbackRate}
|
||||||
ref={this.noticeRef}
|
ref={this.noticeRef}
|
||||||
closeListener={() => this.closeListener()}>
|
closeListener={() => this.closeListener()}>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user