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

Add option to display distraction free titles #2987

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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export default Vue.extend({
hideChapters: function () {
return this.$store.getters.getHideChapters
},
showDistractionFreeTitles: function () {
return this.$store.getters.getShowDistractionFreeTitles
},
channelsHidden: function () {
return JSON.parse(this.$store.getters.getChannelsHidden)
}
Expand Down Expand Up @@ -100,7 +103,8 @@ export default Vue.extend({
'updateHideUpcomingPremieres',
'updateHideSharingActions',
'updateHideChapters',
'updateChannelsHidden'
'updateChannelsHidden',
'updateShowDistractionFreeTitles'
])
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
:default-value="hideComments"
@change="updateHideComments"
/>
<ft-toggle-switch
:label="$t('Settings.Distraction Free Settings.Display Titles Without Excessive Capitalisation')"
:compact="true"
:default-value="showDistractionFreeTitles"
@change="updateShowDistractionFreeTitles"
/>
</div>
</div>
<br class="hide-on-mobile">
Expand Down
16 changes: 14 additions & 2 deletions src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
formatDurationAsTimestamp,
openExternalLink,
showToast,
toLocalePublicationString
toLocalePublicationString,
toDistractionFreeTitle,

} from '../../helpers/utils'

export default Vue.extend({
Expand Down Expand Up @@ -282,7 +284,17 @@ export default Vue.extend({

currentLocale: function () {
return i18n.locale.replace('_', '-')
}
},
showDistractionFreeTitles: function () {
return this.$store.getters.getShowDistractionFreeTitles
},
displayTitle: function () {
if (this.showDistractionFreeTitles) {
return toDistractionFreeTitle(this.data.title)
} else {
return this.data.title
}
},
},
mounted: function () {
this.parseVideoData()
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ft-list-video/ft-list-video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
query: playlistId ? {playlistId} : {}
}"
>
{{ title }}
{{ displayTitle }}
</router-link>
<div class="infoLine">
<router-link
Expand Down
23 changes: 23 additions & 0 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,26 @@ export function getVideoParamsFromUrl(url) {

return extractors.reduce((a, c) => a || c(), null) || paramsObject
}

/**
* This will match sequences of upper case characters and convert them into title cased words.
* @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
*/
export function toDistractionFreeTitle(title, minUpperCase = 3) {
const firstValidCharIndex = (word) => {
const reg = /[\p{L}]/u
return word.search(reg)
}

const capitalizedWord = (word) => {
const chars = word.split('')
const index = firstValidCharIndex(word)
chars[index] = chars[index].toUpperCase()
return chars.join('')
}

const reg = RegExp(`[\\p{Lu}|']{${minUpperCase},}`, 'ug')
return title.replace(reg, x => capitalizedWord(x.toLowerCase()))
}
1 change: 1 addition & 0 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ const state = {
hideWatchedSubs: false,
hideLabelsSideBar: false,
hideChapters: false,
showDistractionFreeTitles: false,
landingPage: 'subscriptions',
listType: 'grid',
maxVideoPlaybackRate: 3,
Expand Down
1 change: 1 addition & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ Settings:
Hide Active Subscriptions: Hide Active Subscriptions
Hide Video Description: Hide Video Description
Hide Comments: Hide Comments
Display Titles Without Excessive Capitalisation: Display Titles Without Excessive Capitalisation
Hide Live Streams: Hide Live Streams
Hide Upcoming Premieres: Hide Upcoming Premieres
Hide Sharing Actions: Hide Sharing Actions
Expand Down