Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/titles/titleRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { VideoID, getVideoID } from "../../maze-utils/src/video";
import Config, { TitleFormatting } from "../config/config";
import Config from "../config/config";
import { getVideoTitleIncludingUnsubmitted } from "../dataFetching";
import { logError } from "../utils/logger";
import { MobileFix, addNodeToListenFor, getOrCreateTitleButtonContainer } from "../utils/titleBar";
import { BrandingLocation, ShowCustomBrandingInfo, extractVideoIDFromElement, getActualShowCustomBranding, hasCustomTitle, setShowCustomBasedOnDefault, shouldShowCasual, showThreeShowOriginalStages, toggleShowCustom } from "../videoBranding/videoBranding";
import { cleanEmojis, formatTitle } from "./titleFormatter";
import { formatTitle } from "./titleFormatter";
import { setCurrentVideoTitle } from "./pageTitleHandler";
import { getTitleFormatting, shouldCleanEmojis, shouldDefaultToCustom, shouldReplaceTitles, shouldReplaceTitlesFastCheck, shouldUseCrowdsourcedTitles } from "../config/channelOverrides";
import { shouldDefaultToCustom, shouldReplaceTitles, shouldReplaceTitlesFastCheck, shouldUseCrowdsourcedTitles } from "../config/channelOverrides";
import { countTitleReplacement } from "../config/stats";
import { isOnV3Extension, onMobile } from "../../maze-utils/src/pageInfo";
import { isFirefoxOrSafari, waitFor } from "../../maze-utils/src";
Expand Down Expand Up @@ -74,14 +74,7 @@ export async function replaceTitle(element: HTMLElement, videoID: VideoID, showC
if (!await isOnCorrectVideo(element, brandingLocation, videoID)) return false;

const title = titleData?.title;
const originalTitle = getOriginalTitleText(originalTitleElement, brandingLocation).trim();
if (title && await shouldUseCrowdsourcedTitles(videoID)
// If there are just formatting changes, and the user doesn't want those, don't replace
&& (await getTitleFormatting(videoID) !== TitleFormatting.Disable || originalTitle.toLowerCase() !== title.toLowerCase())
&& (await getTitleFormatting(videoID) !== TitleFormatting.Disable
|| await shouldCleanEmojis(videoID) || cleanEmojis(originalTitle.toLowerCase()) !== cleanEmojis(title.toLowerCase()))
&& (!await shouldShowCasual(videoID, element, showCustomBranding, brandingLocation)
|| (originalTitle.toLowerCase() === title.toLowerCase() && await getTitleFormatting(videoID) !== TitleFormatting.Disable))) {
if (title && await shouldUseCrowdsourcedTitles(videoID)) {
const formattedTitle = await formatTitle(title, true, videoID);
if (!await isOnCorrectVideo(element, brandingLocation, videoID)) return false;

Expand Down Expand Up @@ -825,4 +818,4 @@ function getOriginalTitleText(originalTitleElement: HTMLElement, brandingLocatio
default:
return originalTitleElement?.textContent ?? "";
}
}
}
8 changes: 2 additions & 6 deletions src/videoBranding/videoBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Config, { ThumbnailCacheOption, TitleFormatting } from "../config/config"
import { logError } from "../utils/logger";
import { getVideoCasualInfo, getVideoTitleIncludingUnsubmitted } from "../dataFetching";
import { handleOnboarding } from "./onboarding";
import { cleanEmojis, cleanResultingTitle } from "../titles/titleFormatter";
import { getTitleFormatting, shouldDefaultToCustom, shouldDefaultToCustomFastCheck, shouldUseCrowdsourcedTitles } from "../config/channelOverrides";
import { isOnV3Extension, onMobile } from "../../maze-utils/src/pageInfo";
import { addMaxTitleLinesCssToPage } from "../utils/cssInjector";
Expand Down Expand Up @@ -558,10 +557,7 @@ export function setupOptionChangeListener(): void {

async function hasCustomTitleWithOriginalTitle(videoID: VideoID, originalTitleElement: HTMLElement, brandingLocation: BrandingLocation): Promise<boolean> {
const title = await getVideoTitleIncludingUnsubmitted(videoID, brandingLocation);
const originalTitle = originalTitleElement?.textContent;
const customTitle = title && !title.original
&& (!originalTitle || (cleanResultingTitle(cleanEmojis(title.title))).toLowerCase() !== (cleanResultingTitle(cleanEmojis(originalTitle))).toLowerCase())
&& await shouldUseCrowdsourcedTitles(videoID);
const customTitle = title && await shouldUseCrowdsourcedTitles(videoID);

return !!customTitle;
}
Expand Down Expand Up @@ -609,4 +605,4 @@ export async function showThreeShowOriginalStages(videoID: VideoID, originalTitl
return await shouldShowCasualOnVideoWithOriginalTitleElement(videoID, originalTitleElement, brandingLocation)
&& await hasCustomTitleWithOriginalTitle(videoID, originalTitleElement, brandingLocation)
&& await shouldDefaultToCustom(videoID);
}
}