diff options
author | Ajay Ramachandran <[email protected]> | 2021-08-20 13:28:31 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2021-08-20 13:28:31 -0400 |
commit | 6714dbb73f5b7f32c7f7408902296a35ad931fea (patch) | |
tree | 793c512809561423c8c54d5d3c2678a84771c75f /src/render/Tooltip.tsx | |
parent | 32c512a12c9fee48e76c75f64fde859381efc57b (diff) | |
parent | 989b5c9370414a67ef115d9040443cddd578b869 (diff) | |
download | SponsorBlock-6714dbb73f5b7f32c7f7408902296a35ad931fea.tar.gz SponsorBlock-6714dbb73f5b7f32c7f7408902296a35ad931fea.zip |
Merge branch 'master' of https://github.com/ajayyy/SponsorBlock into seleniumselenium
Diffstat (limited to 'src/render/Tooltip.tsx')
-rw-r--r-- | src/render/Tooltip.tsx | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/render/Tooltip.tsx b/src/render/Tooltip.tsx new file mode 100644 index 00000000..7bb2e1f3 --- /dev/null +++ b/src/render/Tooltip.tsx @@ -0,0 +1,73 @@ +import * as React from "react"; +import * as ReactDOM from "react-dom"; + +export interface TooltipProps { + text: string, + link?: string, + referenceNode: HTMLElement, + prependElement?: HTMLElement, // Element to append before + bottomOffset?: string + timeout?: number; +} + +export class Tooltip { + text: string; + container: HTMLDivElement; + + timer: NodeJS.Timeout; + + constructor(props: TooltipProps) { + props.bottomOffset ??= "70px"; + this.text = props.text; + + this.container = document.createElement('div'); + this.container.id = "sponsorTooltip" + props.text; + this.container.style.display = "relative"; + + if (props.prependElement) { + props.referenceNode.insertBefore(this.container, props.prependElement); + } else { + props.referenceNode.appendChild(this.container); + } + + if (props.timeout) { + this.timer = setTimeout(() => this.close(), props.timeout * 1000); + } + + ReactDOM.render( + <div style={{bottom: props.bottomOffset}} + className="sponsorBlockTooltip" > + <div> + <img className="sponsorSkipLogo sponsorSkipObject" + src={chrome.extension.getURL("icons/IconSponsorBlocker256px.png")}> + </img> + <span className="sponsorSkipObject"> + {this.text + (props.link ? ". " : "")} + {props.link ? + <a style={{textDecoration: "underline"}} + target="_blank" + rel="noopener noreferrer" + href={props.link}> + {chrome.i18n.getMessage("LearnMore")} + </a> + : null} + </span> + </div> + <button className="sponsorSkipObject sponsorSkipNoticeButton" + style ={{float: "right" }} + onClick={() => this.close()}> + + {chrome.i18n.getMessage("GotIt")} + </button> + </div>, + this.container + ) + } + + close(): void { + ReactDOM.unmountComponentAtNode(this.container); + this.container.remove(); + + if (this.timer) clearTimeout(this.timer); + } +}
\ No newline at end of file |