mirror of
https://github.com/FreeTubeApp/FreeTube
synced 2024-12-14 13:40:03 +01:00
Merge pull request #143 from Deedone/timestamps
Make timestamps clickable
This commit is contained in:
commit
2d66b97328
@ -0,0 +1,26 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
export default Vue.extend({
|
||||
name: 'FtTimestampCatcher',
|
||||
props: {
|
||||
inputHTML: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
catchTimestampClick: function(event) {
|
||||
const match = event.detail.match(/(\d+):(\d+):?(\d+)?/)
|
||||
if (match[3] !== undefined) { // HH:MM:SS
|
||||
const seconds = 3600 * Number(match[1]) + 60 * Number(match[2]) + Number(match[3])
|
||||
this.$emit('timestampEvent', seconds)
|
||||
} else { // MM:SS
|
||||
const seconds = 60 * Number(match[1]) + Number(match[2])
|
||||
this.$emit('timestampEvent', seconds)
|
||||
}
|
||||
},
|
||||
detectTimestamps: function (input) {
|
||||
return input.replaceAll(/(\d+(:\d+)+)/g, '<a href="#" onclick="this.dispatchEvent(new CustomEvent(\'timestampClicked\',{bubbles:true, detail:\'$1\'}))">$1</a>')
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,9 @@
|
||||
<template>
|
||||
<p
|
||||
@timestampClicked="catchTimestampClick"
|
||||
v-html="detectTimestamps(inputHTML)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script src="./ft-timestamp-catcher.js" />
|
||||
<style scoped src="./ft-timestamp-catcher.css" />
|
@ -3,12 +3,14 @@ import { mapActions } from 'vuex'
|
||||
import FtCard from '../ft-card/ft-card.vue'
|
||||
import FtLoader from '../../components/ft-loader/ft-loader.vue'
|
||||
import CommentScraper from 'yt-comment-scraper'
|
||||
import FtTimestampCatcher from '../../components/ft-timestamp-catcher/ft-timestamp-catcher.vue'
|
||||
|
||||
export default Vue.extend({
|
||||
name: 'WatchVideoComments',
|
||||
components: {
|
||||
'ft-card': FtCard,
|
||||
'ft-loader': FtLoader
|
||||
'ft-loader': FtLoader,
|
||||
'ft-timestamp-catcher': FtTimestampCatcher
|
||||
},
|
||||
props: {
|
||||
id: {
|
||||
@ -39,6 +41,10 @@ export default Vue.extend({
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onTimestamp: function(timestamp) {
|
||||
this.$emit('timestampEvent', timestamp)
|
||||
},
|
||||
|
||||
getCommentData: function () {
|
||||
this.isLoading = true
|
||||
switch (this.backendPreference) {
|
||||
|
@ -46,9 +46,11 @@
|
||||
{{ comment.time }}
|
||||
</span>
|
||||
</p>
|
||||
<p class="commentText">
|
||||
{{ comment.text }}
|
||||
</p>
|
||||
<ft-timestamp-catcher
|
||||
class="commentText"
|
||||
:inputHTML="comment.text"
|
||||
@timestampEvent="onTimestamp"
|
||||
/>
|
||||
<p class="commentLikeCount">
|
||||
<font-awesome-icon
|
||||
icon="thumbs-up"
|
||||
|
@ -1,11 +1,13 @@
|
||||
import Vue from 'vue'
|
||||
import FtCard from '../ft-card/ft-card.vue'
|
||||
import FtTimestampCatcher from '../ft-timestamp-catcher/ft-timestamp-catcher.vue'
|
||||
import autolinker from 'autolinker'
|
||||
|
||||
export default Vue.extend({
|
||||
name: 'WatchVideoDescription',
|
||||
components: {
|
||||
'ft-card': FtCard
|
||||
'ft-card': FtCard,
|
||||
'ft-timestamp-catcher': FtTimestampCatcher
|
||||
},
|
||||
props: {
|
||||
published: {
|
||||
@ -34,6 +36,9 @@ export default Vue.extend({
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onTimestamp: function(timestamp) {
|
||||
this.$emit('timestampEvent', timestamp)
|
||||
},
|
||||
parseDescriptionHtml: function (descriptionText) {
|
||||
descriptionText = descriptionText.replace(/target="_blank"/g, '')
|
||||
descriptionText = descriptionText.replace(/\/redirect.+?(?=q=)/g, '')
|
||||
|
@ -1,8 +1,9 @@
|
||||
<template>
|
||||
<ft-card class="videoDescription">
|
||||
<p
|
||||
<ft-timestamp-catcher
|
||||
class="description"
|
||||
v-html="shownDescription"
|
||||
:inputHTML="shownDescription"
|
||||
@timestampEvent="onTimestamp"
|
||||
/>
|
||||
</ft-card>
|
||||
</template>
|
||||
|
@ -166,6 +166,9 @@ export default Vue.extend({
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
changeTimestamp: function(timestamp) {
|
||||
this.$refs.videoPlayer.player.currentTime(timestamp)
|
||||
},
|
||||
toggleTheatreMode: function() {
|
||||
this.useTheatreMode = !this.useTheatreMode
|
||||
},
|
||||
|
@ -86,12 +86,14 @@
|
||||
:description-html="videoDescriptionHtml"
|
||||
class="watchVideo"
|
||||
:class="{ theatreWatchVideo: useTheatreMode }"
|
||||
@timestampEvent="changeTimestamp"
|
||||
/>
|
||||
<watch-video-comments
|
||||
v-if="!isLoading && !isLive"
|
||||
:id="videoId"
|
||||
class="watchVideo"
|
||||
:class="{ theatreWatchVideo: useTheatreMode }"
|
||||
@timestampEvent="changeTimestamp"
|
||||
/>
|
||||
</div>
|
||||
<div class="sidebarArea">
|
||||
|
Loading…
Reference in New Issue
Block a user