Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove excessive punctuation as part of distraction settings #4673

Merged
Merged
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
8 changes: 6 additions & 2 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,10 @@ export function getVideoParamsFromUrl(url) {

/**
* This will match sequences of upper case characters and convert them into title cased words.
* This will also match excessive strings of punctionation and convert them to one representative character
* @param {string} title the title to process
* @param {number} minUpperCase the minimum number of consecutive upper case characters to match
* @returns {string} the title with upper case characters removed
* @returns {string} the title with upper case characters removed and punctuation normalized
*/
export function toDistractionFreeTitle(title, minUpperCase = 3) {
const firstValidCharIndex = (word) => {
Expand All @@ -634,7 +635,10 @@ export function toDistractionFreeTitle(title, minUpperCase = 3) {
}

const reg = RegExp(`[\\p{Lu}|']{${minUpperCase},}`, 'ug')
return title.replace(reg, x => capitalizedWord(x.toLowerCase()))
return title
.replaceAll(/!{2,}/g, '!')
.replaceAll(/[!?]{2,}/g, '?')
.replace(reg, x => capitalizedWord(x.toLowerCase()))
}

export function formatNumber(number, options = undefined) {
Expand Down
2 changes: 1 addition & 1 deletion static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ Settings:
Hide Video Description: Hide Video Description
Hide Comments: Hide Comments
Hide Profile Pictures in Comments: Hide Profile Pictures in Comments
Display Titles Without Excessive Capitalisation: Display Titles Without Excessive Capitalisation
Display Titles Without Excessive Capitalisation: Display Titles Without Excessive Capitalisation And Punctuation
Hide Live Streams: Hide Live Streams
Hide Upcoming Premieres: Hide Upcoming Premieres
Hide Sharing Actions: Hide Sharing Actions
Expand Down
Loading