mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 21:17:20 +03:00
Better title text for full video labels
This commit is contained in:
@@ -594,7 +594,7 @@ input::-webkit-inner-spin-button {
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sponsorBlockTooltip::after {
|
.sponsorBlockTooltip.sbTriangle::after {
|
||||||
content: " ";
|
content: " ";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 100%;
|
top: 100%;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { downvoteButtonColor, SkipNoticeAction } from "../utils/noticeUtils";
|
|||||||
import { VoteResponse } from "../messageTypes";
|
import { VoteResponse } from "../messageTypes";
|
||||||
import { AnimationUtils } from "../utils/animationUtils";
|
import { AnimationUtils } from "../utils/animationUtils";
|
||||||
import { GenericUtils } from "../utils/genericUtils";
|
import { GenericUtils } from "../utils/genericUtils";
|
||||||
|
import { Tooltip } from "../render/Tooltip";
|
||||||
|
|
||||||
export interface CategoryPillProps {
|
export interface CategoryPillProps {
|
||||||
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
||||||
@@ -21,6 +22,8 @@ export interface CategoryPillState {
|
|||||||
|
|
||||||
class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryPillState> {
|
class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryPillState> {
|
||||||
|
|
||||||
|
tooltip?: Tooltip;
|
||||||
|
|
||||||
constructor(props: CategoryPillProps) {
|
constructor(props: CategoryPillProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
@@ -41,8 +44,10 @@ class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryP
|
|||||||
return (
|
return (
|
||||||
<span style={style}
|
<span style={style}
|
||||||
className={"sponsorBlockCategoryPill"}
|
className={"sponsorBlockCategoryPill"}
|
||||||
title={this.getTitleText()}
|
aria-label={this.getTitleText()}
|
||||||
onClick={(e) => this.toggleOpen(e)}>
|
onClick={(e) => this.toggleOpen(e)}
|
||||||
|
onMouseEnter={() => this.openTooltip()}
|
||||||
|
onMouseLeave={() => this.closeTooltip()}>
|
||||||
<span className="sponsorBlockCategoryPillTitleSection">
|
<span className="sponsorBlockCategoryPillTitleSection">
|
||||||
<img className="sponsorSkipLogo sponsorSkipObject"
|
<img className="sponsorSkipLogo sponsorSkipObject"
|
||||||
src={chrome.extension.getURL("icons/IconSponsorBlocker256px.png")}>
|
src={chrome.extension.getURL("icons/IconSponsorBlocker256px.png")}>
|
||||||
@@ -134,6 +139,26 @@ class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private openTooltip(): void {
|
||||||
|
const tooltipMount = document.querySelector("ytd-video-primary-info-renderer > #container") as HTMLElement;
|
||||||
|
if (tooltipMount) {
|
||||||
|
this.tooltip = new Tooltip({
|
||||||
|
text: this.getTitleText(),
|
||||||
|
referenceNode: tooltipMount,
|
||||||
|
bottomOffset: "70px",
|
||||||
|
opacity: 0.95,
|
||||||
|
displayTriangle: false,
|
||||||
|
showLogo: false,
|
||||||
|
showGotIt: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private closeTooltip(): void {
|
||||||
|
this.tooltip?.close();
|
||||||
|
this.tooltip = null;
|
||||||
|
}
|
||||||
|
|
||||||
getTitleText(): string {
|
getTitleText(): string {
|
||||||
const shortDescription = chrome.i18n.getMessage(`category_${this.state.segment?.category}_pill`);
|
const shortDescription = chrome.i18n.getMessage(`category_${this.state.segment?.category}_pill`);
|
||||||
return (shortDescription ? shortDescription + ". ": "") + chrome.i18n.getMessage("categoryPillTitleText");
|
return (shortDescription ? shortDescription + ". ": "") + chrome.i18n.getMessage("categoryPillTitleText");
|
||||||
|
|||||||
37
src/components/TooltipComponent.tsx
Normal file
37
src/components/TooltipComponent.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import Config from "../config";
|
||||||
|
import { Category, SegmentUUID, SponsorTime } from "../types";
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -9,6 +9,9 @@ export interface TooltipProps {
|
|||||||
bottomOffset?: string
|
bottomOffset?: string
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
opacity?: number;
|
opacity?: number;
|
||||||
|
displayTriangle?: boolean;
|
||||||
|
showLogo: boolean;
|
||||||
|
showGotIt: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Tooltip {
|
export class Tooltip {
|
||||||
@@ -20,6 +23,9 @@ export class Tooltip {
|
|||||||
constructor(props: TooltipProps) {
|
constructor(props: TooltipProps) {
|
||||||
props.bottomOffset ??= "70px";
|
props.bottomOffset ??= "70px";
|
||||||
props.opacity ??= 0.7;
|
props.opacity ??= 0.7;
|
||||||
|
props.displayTriangle ??= true;
|
||||||
|
props.showLogo ??= true;
|
||||||
|
props.showGotIt ??= true;
|
||||||
this.text = props.text;
|
this.text = props.text;
|
||||||
|
|
||||||
this.container = document.createElement('div');
|
this.container = document.createElement('div');
|
||||||
@@ -40,11 +46,13 @@ export class Tooltip {
|
|||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<div style={{bottom: props.bottomOffset, backgroundColor}}
|
<div style={{bottom: props.bottomOffset, backgroundColor}}
|
||||||
className="sponsorBlockTooltip" >
|
className={"sponsorBlockTooltip" + (props.displayTriangle ? " sbTriangle" : "")} >
|
||||||
<div>
|
<div>
|
||||||
<img className="sponsorSkipLogo sponsorSkipObject"
|
{props.showLogo ?
|
||||||
src={chrome.extension.getURL("icons/IconSponsorBlocker256px.png")}>
|
<img className="sponsorSkipLogo sponsorSkipObject"
|
||||||
</img>
|
src={chrome.extension.getURL("icons/IconSponsorBlocker256px.png")}>
|
||||||
|
</img>
|
||||||
|
: null}
|
||||||
<span className="sponsorSkipObject">
|
<span className="sponsorSkipObject">
|
||||||
{this.text + (props.link ? ". " : "")}
|
{this.text + (props.link ? ". " : "")}
|
||||||
{props.link ?
|
{props.link ?
|
||||||
@@ -53,16 +61,18 @@ export class Tooltip {
|
|||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
href={props.link}>
|
href={props.link}>
|
||||||
{chrome.i18n.getMessage("LearnMore")}
|
{chrome.i18n.getMessage("LearnMore")}
|
||||||
</a>
|
</a>
|
||||||
: null}
|
: null}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<button className="sponsorSkipObject sponsorSkipNoticeButton"
|
{props.showGotIt ?
|
||||||
style ={{float: "right" }}
|
<button className="sponsorSkipObject sponsorSkipNoticeButton"
|
||||||
onClick={() => this.close()}>
|
style ={{float: "right" }}
|
||||||
|
onClick={() => this.close()}>
|
||||||
|
|
||||||
{chrome.i18n.getMessage("GotIt")}
|
{chrome.i18n.getMessage("GotIt")}
|
||||||
</button>
|
</button>
|
||||||
|
: null}
|
||||||
</div>,
|
</div>,
|
||||||
this.container
|
this.container
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user