diff options
author | Ajay <[email protected]> | 2024-02-27 22:13:58 -0500 |
---|---|---|
committer | Ajay <[email protected]> | 2024-02-27 22:13:58 -0500 |
commit | 1909e66c87fad875ac22683e524071fc88fb97dc (patch) | |
tree | 6401875cdabd9d2a06347f44446dd109072e3dbe /src | |
parent | 5f8447ec6be56dd24bc45d3c5f6399499946a022 (diff) | |
download | SponsorBlock-1909e66c87fad875ac22683e524071fc88fb97dc.tar.gz SponsorBlock-1909e66c87fad875ac22683e524071fc88fb97dc.zip |
Move category pill to top if on description on right layout
Diffstat (limited to 'src')
-rw-r--r-- | src/components/CategoryPillComponent.tsx | 10 | ||||
-rw-r--r-- | src/render/CategoryPill.tsx | 12 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/components/CategoryPillComponent.tsx b/src/components/CategoryPillComponent.tsx index 36e31b47..e4c5a3ed 100644 --- a/src/components/CategoryPillComponent.tsx +++ b/src/components/CategoryPillComponent.tsx @@ -23,12 +23,14 @@ export interface CategoryPillState { } class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryPillState> { - + mainRef: React.MutableRefObject<HTMLSpanElement>; tooltip?: Tooltip; constructor(props: CategoryPillProps) { super(props); + this.mainRef = React.createRef(); + this.state = { segment: null, show: false, @@ -43,13 +45,17 @@ class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryP color: this.getTextColor(), } + // To be able to remove the margin from the parent + this.mainRef?.current?.parentElement?.classList?.toggle("cbPillOpen", this.state.show); + return ( <span style={style} className={"sponsorBlockCategoryPill" + (!this.props.showTextByDefault ? " sbPillNoText" : "")} aria-label={this.getTitleText()} onClick={(e) => this.toggleOpen(e)} onMouseEnter={() => this.openTooltip()} - onMouseLeave={() => this.closeTooltip()}> + onMouseLeave={() => this.closeTooltip()} + ref={this.mainRef}> <span className="sponsorBlockCategoryPillTitleSection"> <img className="sponsorSkipLogo sponsorSkipObject" diff --git a/src/render/CategoryPill.tsx b/src/render/CategoryPill.tsx index 57730af9..20923fba 100644 --- a/src/render/CategoryPill.tsx +++ b/src/render/CategoryPill.tsx @@ -43,9 +43,15 @@ export class CategoryPill { } private async attachToPageInternal(): Promise<void> { - const referenceNode = + let referenceNode = await waitFor(() => getYouTubeTitleNode()); + // Experimental YouTube layout with description on right + const isOnDescriptionOnRightLayout = document.querySelector("#title #description"); + if (isOnDescriptionOnRightLayout) { + referenceNode = referenceNode.parentElement; + } + if (referenceNode && !referenceNode.contains(this.container)) { if (!this.container) { this.container = document.createElement('span'); @@ -91,7 +97,9 @@ export class CategoryPill { parent.appendChild(this.container); referenceNode.prepend(parent); - referenceNode.style.display = "flex"; + if (!isOnDescriptionOnRightLayout) { + referenceNode.style.display = "flex"; + } } } |