diff options
author | Ajay <[email protected]> | 2023-06-30 02:46:27 -0400 |
---|---|---|
committer | Ajay <[email protected]> | 2023-06-30 02:46:27 -0400 |
commit | e1982f265ef43cd63dd7120b0ae6547e28b14d07 (patch) | |
tree | 70257184289acbc775a59ebe3d482fc7af12d868 | |
parent | e2a01bb74429814e64a14859f43b5fbe2fecdc98 (diff) | |
download | SponsorBlock-e1982f265ef43cd63dd7120b0ae6547e28b14d07.tar.gz SponsorBlock-e1982f265ef43cd63dd7120b0ae6547e28b14d07.zip |
Move maze utils to a submodule, move tooltip out
-rw-r--r-- | .gitmodules | 3 | ||||
m--------- | maze-utils | 0 | ||||
-rw-r--r-- | src/components/TooltipComponent.tsx | 35 | ||||
l--------- | src/maze-utils | 1 | ||||
-rw-r--r-- | src/render/GenericNotice.tsx | 3 | ||||
-rw-r--r-- | src/render/Tooltip.tsx | 153 | ||||
-rw-r--r-- | src/types.ts | 5 | ||||
-rw-r--r-- | webpack/webpack.common.js | 3 |
8 files changed, 11 insertions, 192 deletions
diff --git a/.gitmodules b/.gitmodules index f8e6a71f..19ee9032 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "public/_locales"] path = public/_locales url = https://github.com/ajayyy/ExtensionTranslations +[submodule "maze-utils"] + path = maze-utils + url = https://github.com/ajayyy/maze-utils diff --git a/maze-utils b/maze-utils new file mode 160000 +Subproject 6c30e0993198ec6918d620b34ab03bb0c7fc116 diff --git a/src/components/TooltipComponent.tsx b/src/components/TooltipComponent.tsx deleted file mode 100644 index 0e13c63c..00000000 --- a/src/components/TooltipComponent.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import * as React from "react"; - -export interface TooltipProps { - text: string; - show: boolean; -} - -export interface TooltipState { - -} - -class TooltipComponent extends React.Component<TooltipProps, TooltipState> { - - constructor(props: TooltipProps) { - super(props); - } - - render(): React.ReactElement { - const style: React.CSSProperties = { - display: this.props.show ? "flex" : "none", - position: "absolute", - } - - return ( - <span style={style} - className={"sponsorBlockTooltip"} > - <span className="sponsorBlockTooltipText"> - {this.props.text} - </span> - </span> - ); - } -} - -export default TooltipComponent; diff --git a/src/maze-utils b/src/maze-utils new file mode 120000 index 00000000..a31448d9 --- /dev/null +++ b/src/maze-utils @@ -0,0 +1 @@ +../maze-utils/src/
\ No newline at end of file diff --git a/src/render/GenericNotice.tsx b/src/render/GenericNotice.tsx index f3cc7a2e..d3dc4f95 100644 --- a/src/render/GenericNotice.tsx +++ b/src/render/GenericNotice.tsx @@ -5,8 +5,9 @@ import NoticeComponent from "../components/NoticeComponent"; import Utils from "../utils"; const utils = new Utils(); -import { ButtonListener, ContentContainer } from "../types"; +import { ContentContainer } from "../types"; import NoticeTextSelectionComponent from "../components/NoticeTextSectionComponent"; +import { ButtonListener } from "../../maze-utils/src/components/component-types"; export interface TextBox { icon: string; diff --git a/src/render/Tooltip.tsx b/src/render/Tooltip.tsx index 22e4ab09..d08c0f61 100644 --- a/src/render/Tooltip.tsx +++ b/src/render/Tooltip.tsx @@ -1,154 +1,7 @@ -import * as React from "react"; -import { createRoot, Root } from 'react-dom/client'; -import { ButtonListener } from "../types"; -import { isFirefoxOrSafari } from "@ajayyy/maze-utils"; -import { isSafari } from "@ajayyy/maze-utils/lib/config"; +import { GenericTooltip, TooltipProps } from "../../maze-utils/src/components/Tooltip"; -export interface TooltipProps { - text?: string; - link?: string; - linkOnClick?: () => void; - referenceNode: HTMLElement; - prependElement?: HTMLElement; // Element to append before - bottomOffset?: string; - topOffset?: string; - leftOffset?: string; - rightOffset?: string; - timeout?: number; - opacity?: number; - displayTriangle?: boolean; - extraClass?: string; - showLogo?: boolean; - showGotIt?: boolean; - center?: boolean; - positionRealtive?: boolean; - containerAbsolute?: boolean; - buttons?: ButtonListener[]; -} - -export class Tooltip { - text?: string; - container: HTMLDivElement; - - timer: NodeJS.Timeout; - root: Root; - +export class Tooltip extends GenericTooltip { constructor(props: TooltipProps) { - props.bottomOffset ??= "70px"; - props.topOffset ??= "inherit"; - props.leftOffset ??= "inherit"; - props.rightOffset ??= "inherit"; - props.opacity ??= 0.7; - props.displayTriangle ??= true; - props.extraClass ??= ""; - props.showLogo ??= true; - props.showGotIt ??= true; - props.positionRealtive ??= true; - props.containerAbsolute ??= false; - props.center ??= false; - this.text = props.text; - - this.container = document.createElement('div'); - this.container.id = "sponsorTooltip" + props.text; - if (props.positionRealtive) this.container.style.position = "relative"; - if (props.containerAbsolute) this.container.style.position = "absolute"; - if (props.center) { - if (isFirefoxOrSafari() && !isSafari()) { - this.container.style.width = "-moz-available"; - } else { - this.container.style.width = "-webkit-fill-available"; - } - } - - 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); - } - - const backgroundColor = `rgba(28, 28, 28, ${props.opacity})`; - - this.root = createRoot(this.container); - this.root.render( - <div style={{ - bottom: props.bottomOffset, - top: props.topOffset, - left: props.leftOffset, - right: props.rightOffset, - backgroundColor, - margin: props.center ? "auto" : null - }} - className={"sponsorBlockTooltip" + - (props.displayTriangle ? " sbTriangle" : "") + - ` ${props.extraClass}`}> - <div> - {props.showLogo ? - <img className="sponsorSkipLogo sponsorSkipObject" - src={chrome.extension.getURL("icons/IconSponsorBlocker256px.png")}> - </img> - : null} - {this.text ? - <span className={`sponsorSkipObject${!props.showLogo ? ` sponsorSkipObjectFirst` : ``}`}> - {this.text + (props.link ? ". " : "")} - {props.link ? - <a style={{textDecoration: "underline"}} - target="_blank" - rel="noopener noreferrer" - href={props.link}> - {chrome.i18n.getMessage("LearnMore")} - </a> - : (props.linkOnClick ? - <a style={{textDecoration: "underline", marginLeft: "5px", cursor: "pointer"}} - onClick={props.linkOnClick}> - {chrome.i18n.getMessage("LearnMore")} - </a> - : null)} - </span> - : null} - - {this.getButtons(props.buttons)} - </div> - {props.showGotIt ? - <button className="sponsorSkipObject sponsorSkipNoticeButton" - style ={{float: "right" }} - onClick={() => this.close()}> - - {chrome.i18n.getMessage("GotIt")} - </button> - : null} - </div> - ) - } - - getButtons(buttons?: ButtonListener[]): JSX.Element[] { - if (buttons) { - const result: JSX.Element[] = []; - - for (const button of buttons) { - result.push( - <button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton" - key={button.name} - onClick={(e) => button.listener(e)}> - - {button.name} - </button> - ) - } - - return result; - } else { - return null; - } - } - - close(): void { - this.root.unmount(); - this.container.remove(); - - if (this.timer) clearTimeout(this.timer); + super(props, "icons/IconSponsorBlocker256px.png") } }
\ No newline at end of file diff --git a/src/types.ts b/src/types.ts index 4913fdad..9ea0841c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -220,9 +220,4 @@ export enum NoticeVisbilityMode { MiniForAll = 2, FadedForAutoSkip = 3, FadedForAll = 4 -} - -export interface ButtonListener { - name: string; - listener: (e?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void; }
\ No newline at end of file diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 171b2885..e1a3e66c 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -123,7 +123,8 @@ module.exports = env => { ] }, resolve: { - extensions: ['.ts', '.tsx', '.js'] + extensions: ['.ts', '.tsx', '.js'], + symlinks: false }, plugins: [ // Prehook to start building document script before normal build |