Skip to content

Commit

Permalink
* Update description links to not be tabbed into when description box…
Browse files Browse the repository at this point in the history
… collapsed
  • Loading branch information
PikachuEXE committed Dec 28, 2024
1 parent 4ab9c95 commit 67c14f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/renderer/components/FtTimestampCatcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router/composables'
const props = defineProps({
inputHtml: {
type: String,
default: ''
}
},
linkTabIndex: {
type: Number,
default: 0
},
})
const router = useRouter()
const videoId = router.currentRoute.params.id
/** @type {string} */
const displayText = props.inputHtml.replaceAll(/(?:(\d+):)?(\d+):(\d+)/g, (timestamp, hours, minutes, seconds) => {
/** @type {import('vue').ComputedRef<string>} */
const displayText = computed(() => props.inputHtml.replaceAll(/(?:(\d+):)?(\d+):(\d+)/g, (timestamp, hours, minutes, seconds) => {
let time = 60 * Number(minutes) + Number(seconds)
if (hours) {
Expand All @@ -36,8 +41,8 @@ const displayText = props.inputHtml.replaceAll(/(?:(\d+):)?(\d+):(\d+)/g, (times
}).href
// Adding the URL lets the user open the video in a new window at this timestamp
return `<a href="${url}" onclick="event.preventDefault();this.dispatchEvent(new CustomEvent('timestamp-clicked',{bubbles:true,detail:${time}}));window.scrollTo(0,0)">${timestamp}</a>`
})
return `<a tabindex="${props.linkTabIndex}" href="${url}" onclick="event.preventDefault();this.dispatchEvent(new CustomEvent('timestamp-clicked',{bubbles:true,detail:${time}}));window.scrollTo(0,0)">${timestamp}</a>`
}))
const emit = defineEmits(['text-click', 'timestamp-event'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<FtTimestampCatcher
ref="descriptionContainer"
class="description"
:input-html="shownDescription"
:input-html="processedShownDescription"
:link-tab-index="linkTabIndex"
@timestamp-event="onTimestamp"
@text-click="expandDescription"
/>
Expand All @@ -40,7 +41,7 @@
<script setup>
import autolinker from 'autolinker'
import { onMounted, ref } from 'vue'
import { onMounted, ref, computed } from 'vue'
import FtCard from '../ft-card/ft-card.vue'
import FtTimestampCatcher from '../FtTimestampCatcher.vue'
Expand Down Expand Up @@ -81,6 +82,16 @@ if (props.descriptionHtml !== '') {
}
}
const processedShownDescription = computed(() => {
if (shownDescription === '') { return shownDescription }
return processDescriptionHtml(shownDescription, linkTabIndex.value)
})
const linkTabIndex = computed(() => {
return showFullDescription.value ? 0 : -1
})
/**
* @param {number} timestamp
*/
Expand Down Expand Up @@ -144,6 +155,16 @@ function parseDescriptionHtml(descriptionText) {
.replaceAll('href="/hashtag/', 'href="https://wwww.youtube.com/hashtag/')
.replaceAll('yt.www.watch.player.seekTo', 'changeDuration')
}
/**
* @param {string} descriptionText
* @param {number} tabIndex
* @returns {string}
*/
function processDescriptionHtml(descriptionText, tabIndex) {
return descriptionText
.replaceAll('<a', `<a tabindex="${tabIndex}"`)
}
</script>
<style scoped src="./WatchVideoDescription.css" />

0 comments on commit 67c14f8

Please sign in to comment.