FreeTube/src/renderer/components/ft-share-button/ft-share-button.js

152 lines
3.9 KiB
JavaScript
Raw Normal View History

2020-06-17 14:15:36 +02:00
import Vue from 'vue'
2020-09-12 05:20:26 +02:00
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
2020-06-17 14:15:36 +02:00
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import FtButton from '../ft-button/ft-button.vue'
2020-09-12 05:20:26 +02:00
import FtToggleSwitch from '../ft-toggle-switch/ft-toggle-switch.vue'
2020-07-04 17:44:35 +02:00
import { mapActions } from 'vuex'
2020-06-17 14:15:36 +02:00
export default Vue.extend({
name: 'FtShareButton',
components: {
2020-09-12 05:20:26 +02:00
'ft-flex-box': FtFlexBox,
2020-06-17 14:15:36 +02:00
'ft-icon-button': FtIconButton,
2020-09-12 05:20:26 +02:00
'ft-button': FtButton,
'ft-toggle-switch': FtToggleSwitch
2020-06-17 15:36:44 +02:00
},
props: {
id: {
type: String,
required: true
2020-09-11 05:48:06 +02:00
},
playlistId: {
type: String,
default: ''
},
2020-09-12 05:20:26 +02:00
getTimestamp: {
type: Function,
required: true
}
},
data: function () {
return {
includeTimestamp: false
2020-06-17 15:36:44 +02:00
}
},
computed: {
currentInvidiousInstance: function () {
return this.$store.getters.getCurrentInvidiousInstance
2020-06-17 15:36:44 +02:00
},
2020-06-18 16:53:54 +02:00
invidiousURL() {
let videoUrl = `${this.currentInvidiousInstance}/watch?v=${this.id}`
// `playlistId` can be undefined
if (this.playlistId && this.playlistId.length !== 0) {
// `index` seems can be ignored
videoUrl += `&list=${this.playlistId}`
}
return videoUrl
2020-06-17 15:36:44 +02:00
},
2020-06-18 16:53:54 +02:00
invidiousEmbedURL() {
return `${this.currentInvidiousInstance}/embed/${this.id}`
2020-06-17 15:58:06 +02:00
},
2020-06-18 16:53:54 +02:00
youtubeURL() {
let videoUrl = `https://www.youtube.com/watch?v=${this.id}`
// `playlistId` can be undefined
if (this.playlistId && this.playlistId.length !== 0) {
// `index` seems can be ignored
videoUrl += `&list=${this.playlistId}`
}
return videoUrl
2020-06-17 15:36:44 +02:00
},
youtubeShareURL() {
// `playlistId` can be undefined
if (this.playlistId && this.playlistId.length !== 0) {
// `index` seems can be ignored
return `https://www.youtube.com/watch?v=${this.id}&list=${this.playlistId}`
}
return `https://youtu.be/${this.id}`
},
2020-06-18 16:53:54 +02:00
youtubeEmbedURL() {
2020-06-17 15:36:44 +02:00
return `https://www.youtube-nocookie.com/embed/${this.id}`
}
2020-06-18 16:53:54 +02:00
},
methods: {
copy(text) {
navigator.clipboard.writeText(text)
},
2020-06-17 15:36:44 +02:00
openInvidious() {
this.openExternalLink(this.getFinalUrl(this.invidiousURL))
this.$refs.iconButton.focusOut()
2020-09-11 05:48:06 +02:00
},
2020-06-17 15:36:44 +02:00
copyInvidious() {
this.showToast({
message: this.$t('Share.Invidious URL copied to clipboard')
})
2020-09-12 05:20:26 +02:00
this.copy(this.getFinalUrl(this.invidiousURL))
this.$refs.iconButton.focusOut()
2020-09-11 05:48:06 +02:00
},
2020-06-17 15:36:44 +02:00
openYoutube() {
this.openExternalLink(this.getFinalUrl(this.youtubeURL))
this.$refs.iconButton.focusOut()
2020-09-11 05:48:06 +02:00
},
2020-06-17 15:36:44 +02:00
copyYoutube() {
this.showToast({
message: this.$t('Share.YouTube URL copied to clipboard')
})
this.copy(this.getFinalUrl(this.youtubeShareURL))
this.$refs.iconButton.focusOut()
2020-09-11 05:48:06 +02:00
},
2020-06-17 15:36:44 +02:00
openYoutubeEmbed() {
this.openExternalLink(this.getFinalUrl(this.youtubeEmbedURL))
this.$refs.iconButton.focusOut()
2020-06-17 15:36:44 +02:00
},
copyYoutubeEmbed() {
this.showToast({
message: this.$t('Share.YouTube Embed URL copied to clipboard')
})
2020-09-12 05:20:26 +02:00
this.copy(this.getFinalUrl(this.youtubeEmbedURL))
this.$refs.iconButton.focusOut()
2020-06-17 15:58:06 +02:00
},
openInvidiousEmbed() {
this.openExternalLink(this.getFinalUrl(this.invidiousEmbedURL))
this.$refs.iconButton.focusOut()
2020-06-17 15:58:06 +02:00
},
copyInvidiousEmbed() {
this.showToast({
message: this.$t('Share.Invidious Embed URL copied to clipboard')
})
2020-09-12 05:20:26 +02:00
this.copy(this.getFinalUrl(this.invidiousEmbedURL))
this.$refs.iconButton.focusOut()
2020-06-17 15:58:06 +02:00
},
2020-07-04 17:44:35 +02:00
updateIncludeTimestamp() {
this.includeTimestamp = !this.includeTimestamp
2020-09-12 05:20:26 +02:00
},
getFinalUrl(url) {
2020-11-14 20:21:22 +01:00
if (url.indexOf('?') === -1) {
return this.includeTimestamp ? `${url}?t=${this.getTimestamp()}` : url
}
return this.includeTimestamp ? `${url}&t=${this.getTimestamp()}` : url
2020-09-12 05:20:26 +02:00
},
2020-07-04 17:44:35 +02:00
...mapActions([
'showToast',
'openExternalLink'
2020-07-04 17:44:35 +02:00
])
2020-06-17 14:15:36 +02:00
}
})