From 252da8c56afea294ca2f49585b2353c52fa86611 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 16 May 2020 23:58:02 -0400 Subject: [PATCH] Added the ability to stop the notice timer by clicking it --- manifest/manifest.json | 2 +- public/_locales/en/messages.json | 3 +++ src/components/NoticeComponent.tsx | 33 +++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/manifest/manifest.json b/manifest/manifest.json index 6c077f83..a64cbb13 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "__MSG_Name__", - "version": "1.2.28.3", + "version": "1.2.28.4", "default_locale": "en", "description": "__MSG_Description__", "content_scripts": [{ diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 8793f800..b9859414 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -68,6 +68,9 @@ "paused": { "message": "Paused" }, + "manualPaused": { + "message": "Timer Stopped" + }, "confirmMSG": { "message": "To edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner." }, diff --git a/src/components/NoticeComponent.tsx b/src/components/NoticeComponent.tsx index b7ff8adf..f5e3a7af 100644 --- a/src/components/NoticeComponent.tsx +++ b/src/components/NoticeComponent.tsx @@ -23,6 +23,7 @@ export interface NoticeState { countdownTime: number, countdownText: string, + countdownManuallyPaused: boolean, } class NoticeComponent extends React.Component { @@ -55,6 +56,7 @@ class NoticeComponent extends React.Component { //the countdown until this notice closes countdownTime: maxCountdownTime(), countdownText: null, + countdownManuallyPaused: false } } @@ -71,8 +73,8 @@ class NoticeComponent extends React.Component { + onMouseEnter={() => this.timerMouseEnter()} + onMouseLeave={() => this.timerMouseLeave()}> {/* First row */} @@ -99,6 +101,7 @@ class NoticeComponent extends React.Component { {/* Time left */} {this.props.timed ? ( this.toggleManualPause()} className="sponsorSkipObject sponsorSkipNoticeTimeLeft"> {this.state.countdownText || (this.state.countdownTime + "s")} @@ -121,6 +124,30 @@ class NoticeComponent extends React.Component { ); } + timerMouseEnter() { + if (this.state.countdownManuallyPaused) return; + + this.pauseCountdown(); + } + + timerMouseLeave() { + if (this.state.countdownManuallyPaused) return; + + this.startCountdown(); + } + + toggleManualPause() { + this.setState({ + countdownManuallyPaused: !this.state.countdownManuallyPaused + }, () => { + if (this.state.countdownManuallyPaused) { + this.pauseCountdown(); + } else { + this.startCountdown(); + } + }); + } + //called every second to lower the countdown before hiding the notice countdown() { if (!this.props.timed) return; @@ -159,7 +186,7 @@ class NoticeComponent extends React.Component { //reset countdown and inform the user this.setState({ countdownTime: this.state.maxCountdownTime(), - countdownText: chrome.i18n.getMessage("paused") + countdownText: this.state.countdownManuallyPaused ? chrome.i18n.getMessage("manualPaused") : chrome.i18n.getMessage("paused") }); //remove the fade out class if it exists