mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Add warning when chapter name similar to category
This commit is contained in:
parent
70731e42a5
commit
355572ba04
3 changed files with 43 additions and 19 deletions
|
@ -883,6 +883,9 @@
|
||||||
"categoryPillTitleText": {
|
"categoryPillTitleText": {
|
||||||
"message": "This entire video is labeled as this category and is too tightly integrated to be able to separate"
|
"message": "This entire video is labeled as this category and is too tightly integrated to be able to separate"
|
||||||
},
|
},
|
||||||
|
"chapterNameTooltipWarning": {
|
||||||
|
"message": "One of your chapter names is similar to a category. You should use categories when possible instead."
|
||||||
|
},
|
||||||
"experiementOptOut": {
|
"experiementOptOut": {
|
||||||
"message": "Opt-out of all future experiments",
|
"message": "Opt-out of all future experiments",
|
||||||
"description": "This is used in a popup about a new experiment to get a list of unlisted videos to back up since all unlisted videos uploaded before 2017 will be set to private."
|
"description": "This is used in a popup about a new experiment to get a list of unlisted videos to back up since all unlisted videos uploaded before 2017 will be set to private."
|
||||||
|
|
|
@ -34,6 +34,9 @@ export interface SponsorTimeEditState {
|
||||||
|
|
||||||
const DEFAULT_CATEGORY = "chooseACategory";
|
const DEFAULT_CATEGORY = "chooseACategory";
|
||||||
|
|
||||||
|
const categoryNames = CompileConfig.categoryList.filter((name) => name !== "chapter")
|
||||||
|
.map((name) => chrome.i18n.getMessage("category_" + name));
|
||||||
|
|
||||||
class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, SponsorTimeEditState> {
|
class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, SponsorTimeEditState> {
|
||||||
|
|
||||||
idSuffix: string;
|
idSuffix: string;
|
||||||
|
@ -48,6 +51,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||||
// Used when selecting POI or Full
|
// Used when selecting POI or Full
|
||||||
timesBeforeChanging: number[] = [];
|
timesBeforeChanging: number[] = [];
|
||||||
fullVideoWarningShown = false;
|
fullVideoWarningShown = false;
|
||||||
|
categoryNameWarningShown = false;
|
||||||
|
|
||||||
// For description auto-complete
|
// For description auto-complete
|
||||||
fetchingSuggestions: boolean;
|
fetchingSuggestions: boolean;
|
||||||
|
@ -101,6 +105,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||||
|
|
||||||
render(): React.ReactElement {
|
render(): React.ReactElement {
|
||||||
this.checkToShowFullVideoWarning();
|
this.checkToShowFullVideoWarning();
|
||||||
|
this.checkToShowChapterWarning();
|
||||||
|
|
||||||
const style: React.CSSProperties = {
|
const style: React.CSSProperties = {
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
|
@ -336,13 +341,15 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||||
|
|
||||||
showScrollToEditToolTip(): void {
|
showScrollToEditToolTip(): void {
|
||||||
if (!Config.config.scrollToEditTimeUpdate && document.getElementById("sponsorRectangleTooltip" + "sponsorTimesContainer" + this.idSuffix) === null) {
|
if (!Config.config.scrollToEditTimeUpdate && document.getElementById("sponsorRectangleTooltip" + "sponsorTimesContainer" + this.idSuffix) === null) {
|
||||||
this.showToolTip(chrome.i18n.getMessage("SponsorTimeEditScrollNewFeature"), () => { Config.config.scrollToEditTimeUpdate = true });
|
this.showToolTip(chrome.i18n.getMessage("SponsorTimeEditScrollNewFeature"), "scrollToEdit", () => { Config.config.scrollToEditTimeUpdate = true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showToolTip(text: string, buttonFunction?: () => void): boolean {
|
showToolTip(text: string, id: string, buttonFunction?: () => void): boolean {
|
||||||
const element = document.getElementById("sponsorTimesContainer" + this.idSuffix);
|
const element = document.getElementById("sponsorTimesContainer" + this.idSuffix);
|
||||||
if (element) {
|
if (element) {
|
||||||
|
const htmlId = `sponsorRectangleTooltip${id + this.idSuffix}`;
|
||||||
|
if (!document.getElementById(htmlId)) {
|
||||||
new RectangleTooltip({
|
new RectangleTooltip({
|
||||||
text,
|
text,
|
||||||
referenceNode: element.parentElement,
|
referenceNode: element.parentElement,
|
||||||
|
@ -351,11 +358,12 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||||
bottomOffset: 0 + "px",
|
bottomOffset: 0 + "px",
|
||||||
leftOffset: -318 + "px",
|
leftOffset: -318 + "px",
|
||||||
backgroundColor: "rgba(28, 28, 28, 1.0)",
|
backgroundColor: "rgba(28, 28, 28, 1.0)",
|
||||||
htmlId: "sponsorTimesContainer" + this.idSuffix,
|
htmlId,
|
||||||
buttonFunction,
|
buttonFunction,
|
||||||
fontSize: "14px",
|
fontSize: "14px",
|
||||||
maxHeight: "200px"
|
maxHeight: "200px"
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -370,12 +378,25 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||||
|
|
||||||
if (videoPercentage > 0.6 && !this.fullVideoWarningShown
|
if (videoPercentage > 0.6 && !this.fullVideoWarningShown
|
||||||
&& (sponsorTime.category === "sponsor" || sponsorTime.category === "selfpromo" || sponsorTime.category === "chooseACategory")) {
|
&& (sponsorTime.category === "sponsor" || sponsorTime.category === "selfpromo" || sponsorTime.category === "chooseACategory")) {
|
||||||
if (this.showToolTip(chrome.i18n.getMessage("fullVideoTooltipWarning"))) {
|
if (this.showToolTip(chrome.i18n.getMessage("fullVideoTooltipWarning"), "fullVideoWarning")) {
|
||||||
this.fullVideoWarningShown = true;
|
this.fullVideoWarningShown = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkToShowChapterWarning(): void {
|
||||||
|
const sponsorTime = this.props.contentContainer().sponsorTimesSubmitting[this.props.index];
|
||||||
|
|
||||||
|
if (sponsorTime.actionType === ActionType.Chapter && sponsorTime.description
|
||||||
|
&& !this.categoryNameWarningShown
|
||||||
|
&& categoryNames.some(
|
||||||
|
(category) => sponsorTime.description.toLowerCase().includes(category.toLowerCase()))) {
|
||||||
|
if (this.showToolTip(chrome.i18n.getMessage("chapterNameTooltipWarning"), "chapterWarning")) {
|
||||||
|
this.categoryNameWarningShown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getCategoryOptions(): React.ReactElement[] {
|
getCategoryOptions(): React.ReactElement[] {
|
||||||
const elements = [(
|
const elements = [(
|
||||||
<option value={DEFAULT_CATEGORY}
|
<option value={DEFAULT_CATEGORY}
|
||||||
|
|
|
@ -33,8 +33,8 @@ export class RectangleTooltip {
|
||||||
props.fontSize ??= "10px";
|
props.fontSize ??= "10px";
|
||||||
|
|
||||||
this.container = document.createElement('div');
|
this.container = document.createElement('div');
|
||||||
props.htmlId ??= props.text;
|
props.htmlId ??= "sponsorRectangleTooltip" + props.text;
|
||||||
this.container.id = "sponsorRectangleTooltip" + props.htmlId;
|
this.container.id = props.htmlId;
|
||||||
this.container.style.display = "relative";
|
this.container.style.display = "relative";
|
||||||
|
|
||||||
if (props.prependElement) {
|
if (props.prependElement) {
|
||||||
|
|
Loading…
Reference in a new issue