Skip to content

Commit

Permalink
Add option to only format user submitted titles
Browse files Browse the repository at this point in the history
Fixes #304
  • Loading branch information
ajayyy committed Oct 30, 2024
1 parent 2b047c8 commit cb73464
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 26 deletions.
2 changes: 1 addition & 1 deletion public/_locales
Submodule _locales updated 1 files
+3 −0 en/messages.json
61 changes: 40 additions & 21 deletions public/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,51 @@
<option value="4">__MSG_FirstLetterUppercase__</option>
<option value="0">__MSG_CapitalizeWords__</option>
</select>
</div>

<div data-type="toggle" data-sync="shouldCleanEmojis">
<div class="sb-switch-container">
<label class="sb-switch">
<input id="shouldCleanEmojis" type="checkbox" checked>
<span class="sb-slider sb-round"></span>
</label>
<label class="sb-switch-label" for="shouldCleanEmojis">
__MSG_shouldCleanEmojis__
</label>
<br/>
<br/>

<div data-type="toggle" data-sync="onlyFormatCustomTitles">
<div class="sb-switch-container">
<label class="sb-switch">
<input id="onlyFormatCustomTitles" type="checkbox" checked>
<span class="sb-slider sb-round"></span>
</label>
<label class="sb-switch-label" for="onlyFormatCustomTitles">
__MSG_onlyFormatCustomTitles__
</label>
</div>
</div>
</div>

<div data-type="toggle" data-sync="onlyTitleCaseInEnglish" data-dependent-on-selector="titleFormatting" data-dependent-on-selector-value="1">
<div class="sb-switch-container">
<label class="sb-switch">
<input id="onlyTitleCaseInEnglish" type="checkbox" checked>
<span class="sb-slider sb-round"></span>
</label>
<label class="sb-switch-label" for="onlyTitleCaseInEnglish">
__MSG_onlyTitleCaseInEnglish__
</label>
<br/>

<div data-type="toggle" data-sync="shouldCleanEmojis">
<div class="sb-switch-container">
<label class="sb-switch">
<input id="shouldCleanEmojis" type="checkbox" checked>
<span class="sb-slider sb-round"></span>
</label>
<label class="sb-switch-label" for="shouldCleanEmojis">
__MSG_shouldCleanEmojis__
</label>
</div>
</div>

<div class="small-description">__MSG_onlyTitleCaseInEnglishDescription__</div>
<br/>

<div data-type="toggle" data-sync="onlyTitleCaseInEnglish" data-dependent-on-selector="titleFormatting" data-dependent-on-selector-value="1">
<div class="sb-switch-container">
<label class="sb-switch">
<input id="onlyTitleCaseInEnglish" type="checkbox" checked>
<span class="sb-slider sb-round"></span>
</label>
<label class="sb-switch-label" for="onlyTitleCaseInEnglish">
__MSG_onlyTitleCaseInEnglish__
</label>
</div>

<div class="small-description">__MSG_onlyTitleCaseInEnglishDescription__</div>
</div>
</div>

<div data-type="selector" data-sync="thumbnailFallback">
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ interface SBConfig {
keepUnsubmittedInPrivate: boolean;
thumbnailSaturationLevel: number;
titleFormatting: TitleFormatting;
onlyFormatCustomTitles: boolean;
shouldCleanEmojis: boolean;
onlyTitleCaseInEnglish: boolean;
serverAddress: string;
Expand Down Expand Up @@ -171,6 +172,7 @@ const syncDefaults = {
keepUnsubmittedInPrivate: false,
thumbnailSaturationLevel: 100,
titleFormatting: isEnglish ? TitleFormatting.TitleCase : TitleFormatting.Disable,
onlyFormatCustomTitles: false,
shouldCleanEmojis: true,
onlyTitleCaseInEnglish: false,
serverAddress: CompileConfig.serverAddress,
Expand Down
15 changes: 15 additions & 0 deletions src/popup/FormattingOptionsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const FormattingOptionsComponent = ({
[titleFormatting, setTitleFormatting] = React.useState(Config.config!.titleFormatting);
}

const [onlyFormatCustomTitles, setOnlyFormatCustomTitles] = React.useState(Config.config!.onlyFormatCustomTitles);
const [shouldCleanEmojis, setShouldCleanEmojis] = React.useState(Config.config!.shouldCleanEmojis);
const [onlyTitleCaseInEnglish, setOnlyTitleCaseInEnglish] = React.useState(Config.config!.onlyTitleCaseInEnglish);
const [thumbnailFallback, setThumbnailFallback] = React.useState(String(Config.config!.thumbnailFallback));
Expand Down Expand Up @@ -59,6 +60,20 @@ export const FormattingOptionsComponent = ({
titleFormatting={titleFormatting!}
/>

{/* Only format custom titles */}
<ToggleOptionComponent
id="onlyFormatCustomTitles"
style={{
paddingTop: "15px"
}}
onChange={(value) => {
setOnlyFormatCustomTitles(value);
Config.config!.onlyFormatCustomTitles = value;
}}
value={onlyFormatCustomTitles}
label={chrome.i18n.getMessage("onlyFormatCustomTitles")}
titleFormatting={titleFormatting!}
/>
{/* Should Clean Emojis */}
<ToggleOptionComponent
id="shouldCleanEmojis"
Expand Down
10 changes: 7 additions & 3 deletions src/titles/titleFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ if (LOAD_CLD) {
*/

export async function formatTitle(title: string, isCustom: boolean, videoID: VideoID | null): Promise<string> {
return formatTitleInternal(title, isCustom, await getTitleFormatting(videoID), await shouldCleanEmojis(videoID));
return formatTitleInternal(title, isCustom, await getTitleFormatting(videoID), await shouldCleanEmojis(videoID), Config.config!.onlyFormatCustomTitles);
}

export async function formatTitleDefaultSettings(title: string, isCustom: boolean): Promise<string> {
return await formatTitleInternal(title, isCustom, Config.config!.titleFormatting, Config.config!.shouldCleanEmojis);
return await formatTitleInternal(title, isCustom, Config.config!.titleFormatting, Config.config!.shouldCleanEmojis, Config.config!.onlyFormatCustomTitles);
}

export async function formatTitleInternal(title: string, isCustom: boolean, titleFormatting: TitleFormatting, shouldCleanEmojis: boolean): Promise<string> {
export async function formatTitleInternal(title: string, isCustom: boolean, titleFormatting: TitleFormatting, shouldCleanEmojis: boolean, onlyFormatCustomTitles = false): Promise<string> {
if (shouldCleanEmojis) {
title = cleanFancyText(cleanEmojis(title));
}

if (onlyFormatCustomTitles && !isCustom) {
titleFormatting = TitleFormatting.Disable;
}

switch (titleFormatting) {
case TitleFormatting.CapitalizeWords:
return await toCapitalizeCase(title, isCustom);
Expand Down
3 changes: 2 additions & 1 deletion src/videoBranding/videoBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ export function setupOptionChangeListener(): void {
"showIconForFormattedTitles",
"ignoreAbThumbnails",
"showOriginalOnHover",
"showLiveCover"
"showLiveCover",
"onlyFormatCustomTitles"
];

if (settingsToReload.some((name) => (changes[name] && changes[name].newValue !== changes[name].oldValue))) {
Expand Down

0 comments on commit cb73464

Please sign in to comment.