mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Moved notice closing to renderer (no leftover nodes)
This commit is contained in:
parent
9fafb9cf54
commit
638439a671
5 changed files with 36 additions and 19 deletions
|
@ -11,7 +11,7 @@ export interface NoticeProps {
|
||||||
fadeIn?: boolean,
|
fadeIn?: boolean,
|
||||||
|
|
||||||
// Callback for when this is closed
|
// Callback for when this is closed
|
||||||
closeListener?: () => void,
|
closeListener: () => void,
|
||||||
|
|
||||||
zIndex?: number
|
zIndex?: number
|
||||||
}
|
}
|
||||||
|
@ -195,16 +195,10 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
|
||||||
* @param silent If true, the close listener will not be called
|
* @param silent If true, the close listener will not be called
|
||||||
*/
|
*/
|
||||||
close(silent?: boolean) {
|
close(silent?: boolean) {
|
||||||
//TODO: Change to a listener in the renderer (not component)
|
|
||||||
let notice = document.getElementById("sponsorSkipNotice" + this.idSuffix);
|
|
||||||
if (notice != null) {
|
|
||||||
notice.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
//remove setInterval
|
//remove setInterval
|
||||||
if (this.countdownInterval !== null) clearInterval(this.countdownInterval);
|
if (this.countdownInterval !== null) clearInterval(this.countdownInterval);
|
||||||
|
|
||||||
if (this.props.closeListener && !silent) this.props.closeListener();
|
if (!silent) this.props.closeListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
changeNoticeTitle(title) {
|
changeNoticeTitle(title) {
|
||||||
|
|
|
@ -14,6 +14,8 @@ export interface SkipNoticeProps {
|
||||||
autoSkip: boolean;
|
autoSkip: boolean;
|
||||||
// Contains functions and variables from the content script needed by the skip notice
|
// Contains functions and variables from the content script needed by the skip notice
|
||||||
contentContainer: ContentContainer;
|
contentContainer: ContentContainer;
|
||||||
|
|
||||||
|
closeListener: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SkipNoticeState {
|
export interface SkipNoticeState {
|
||||||
|
@ -112,7 +114,8 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
fadeIn={true}
|
fadeIn={true}
|
||||||
timed={true}
|
timed={true}
|
||||||
maxCountdownTime={this.state.maxCountdownTime}
|
maxCountdownTime={this.state.maxCountdownTime}
|
||||||
ref={this.noticeRef}>
|
ref={this.noticeRef}
|
||||||
|
closeListener={this.props.closeListener}>
|
||||||
|
|
||||||
{(Config.config.audioNotificationOnSkip) && <audio ref={(source) => { this.audio = source; }}>
|
{(Config.config.audioNotificationOnSkip) && <audio ref={(source) => { this.audio = source; }}>
|
||||||
<source src={chrome.extension.getURL("icons/beep.ogg")} type="audio/ogg"></source>
|
<source src={chrome.extension.getURL("icons/beep.ogg")} type="audio/ogg"></source>
|
||||||
|
|
|
@ -11,6 +11,8 @@ export interface SubmissionNoticeProps {
|
||||||
contentContainer: ContentContainer;
|
contentContainer: ContentContainer;
|
||||||
|
|
||||||
callback: () => any;
|
callback: () => any;
|
||||||
|
|
||||||
|
closeListener: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SubmissionNoticeeState {
|
export interface SubmissionNoticeeState {
|
||||||
|
@ -134,6 +136,8 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
|
||||||
this.noticeRef.current.close(true);
|
this.noticeRef.current.close(true);
|
||||||
|
|
||||||
this.contentContainer().resetSponsorSubmissionNotice();
|
this.contentContainer().resetSponsorSubmissionNotice();
|
||||||
|
|
||||||
|
this.props.closeListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
|
|
|
@ -9,6 +9,8 @@ class SkipNotice {
|
||||||
// Contains functions and variables from the content script needed by the skip notice
|
// Contains functions and variables from the content script needed by the skip notice
|
||||||
contentContainer: () => any;
|
contentContainer: () => any;
|
||||||
|
|
||||||
|
noticeElement: HTMLDivElement;
|
||||||
|
|
||||||
constructor(UUID: string, autoSkip: boolean = false, contentContainer) {
|
constructor(UUID: string, autoSkip: boolean = false, contentContainer) {
|
||||||
this.UUID = UUID;
|
this.UUID = UUID;
|
||||||
this.autoSkip = autoSkip;
|
this.autoSkip = autoSkip;
|
||||||
|
@ -35,16 +37,23 @@ class SkipNotice {
|
||||||
//this is the suffix added at the end of every id
|
//this is the suffix added at the end of every id
|
||||||
let idSuffix = this.UUID + amountOfPreviousNotices;
|
let idSuffix = this.UUID + amountOfPreviousNotices;
|
||||||
|
|
||||||
let noticeElement = document.createElement("div");
|
this.noticeElement = document.createElement("div");
|
||||||
noticeElement.id = "sponsorSkipNoticeContainer" + idSuffix;
|
this.noticeElement.id = "sponsorSkipNoticeContainer" + idSuffix;
|
||||||
|
|
||||||
referenceNode.prepend(noticeElement);
|
referenceNode.prepend(this.noticeElement);
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<SkipNoticeComponent UUID={UUID} autoSkip={autoSkip} contentContainer={contentContainer} />,
|
<SkipNoticeComponent UUID={UUID}
|
||||||
noticeElement
|
autoSkip={autoSkip}
|
||||||
|
contentContainer={contentContainer}
|
||||||
|
closeListener={() => this.close()} />,
|
||||||
|
this.noticeElement
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.noticeElement.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SkipNotice;
|
export default SkipNotice;
|
|
@ -11,6 +11,8 @@ class SubmissionNotice {
|
||||||
|
|
||||||
noticeRef: React.MutableRefObject<SubmissionNoticeComponent>;
|
noticeRef: React.MutableRefObject<SubmissionNoticeComponent>;
|
||||||
|
|
||||||
|
noticeElement: HTMLDivElement;
|
||||||
|
|
||||||
constructor(contentContainer: () => any, callback: () => any) {
|
constructor(contentContainer: () => any, callback: () => any) {
|
||||||
this.noticeRef = React.createRef();
|
this.noticeRef = React.createRef();
|
||||||
|
|
||||||
|
@ -34,23 +36,28 @@ class SubmissionNotice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let noticeElement = document.createElement("div");
|
this.noticeElement = document.createElement("div");
|
||||||
noticeElement.id = "submissionNoticeContainer";
|
this.noticeElement.id = "submissionNoticeContainer";
|
||||||
|
|
||||||
referenceNode.prepend(noticeElement);
|
referenceNode.prepend(this.noticeElement);
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<SubmissionNoticeComponent
|
<SubmissionNoticeComponent
|
||||||
contentContainer={contentContainer}
|
contentContainer={contentContainer}
|
||||||
callback={callback}
|
callback={callback}
|
||||||
ref={this.noticeRef} />,
|
ref={this.noticeRef}
|
||||||
noticeElement
|
closeListener={() => this.close()} />,
|
||||||
|
this.noticeElement
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
this.noticeRef.current.forceUpdate();
|
this.noticeRef.current.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.noticeElement.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SubmissionNotice;
|
export default SubmissionNotice;
|
Loading…
Reference in a new issue