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

152 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-06-17 12:15:36 +00:00
import Vue from 'vue'
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import FtButton from '../ft-button/ft-button.vue'
2020-07-04 15:44:35 +00:00
import { mapActions } from 'vuex'
2020-06-17 12:15:36 +00:00
export default Vue.extend({
name: 'FtShareButton',
components: {
'ft-icon-button': FtIconButton,
'ft-button': FtButton
2020-06-17 13:36:44 +00:00
},
props: {
id: {
type: String,
required: true
2020-09-11 03:48:06 +00:00
},
timestamp: {
default: 0,
type: Number
2020-06-17 13:36:44 +00:00
}
},
computed: {
invidiousInstance: function () {
return this.$store.getters.getInvidiousInstance
},
usingElectron: function () {
return this.$store.getters.getUsingElectron
},
2020-06-18 14:53:54 +00:00
invidiousURL() {
2020-06-17 13:36:44 +00:00
return `${this.invidiousInstance}/watch?v=${this.id}`
},
2020-09-11 03:48:06 +00:00
invidiousURLWithTime() {
return `${this.invidiousInstance}/watch?v=${this.id}&t=${this.timestamp}`
},
2020-06-18 14:53:54 +00:00
invidiousEmbedURL() {
2020-06-17 13:58:06 +00:00
return `${this.invidiousInstance}/embed/${this.id}`
},
2020-06-18 14:53:54 +00:00
youtubeURL() {
2020-06-17 13:36:44 +00:00
return `https://www.youtube.com/watch?v=${this.id}`
},
2020-09-11 03:48:06 +00:00
youtubeURLWithTime() {
return `https://www.youtube.com/watch?v=${this.id}&t=${this.timestamp}`
},
2020-06-18 14:53:54 +00:00
youtubeEmbedURL() {
2020-06-17 13:36:44 +00:00
return `https://www.youtube-nocookie.com/embed/${this.id}`
}
2020-06-17 13:36:44 +00:00
2020-06-18 14:53:54 +00:00
},
methods: {
copy(text) {
navigator.clipboard.writeText(text)
},
open(url) {
if (this.usingElectron) {
const shell = require('electron').shell
shell.openExternal(url)
}
},
2020-06-17 13:36:44 +00:00
openInvidious() {
2020-06-18 14:53:54 +00:00
this.open(this.invidiousURL)
this.$refs.iconButton.toggleDropdown()
2020-06-17 13:36:44 +00:00
},
2020-09-11 03:48:06 +00:00
openInvidiousAtTime() {
this.open(this.invidiousURLWithTime)
this.$refs.iconButton.toggleDropdown()
},
2020-06-17 13:36:44 +00:00
copyInvidious() {
this.showToast({
message: this.$t('Share.Invidious URL copied to clipboard')
})
2020-06-18 14:53:54 +00:00
this.copy(this.invidiousURL)
this.$refs.iconButton.toggleDropdown()
2020-06-17 13:36:44 +00:00
},
2020-09-11 03:48:06 +00:00
copyInvidiousAtTime() {
this.showToast({
message: this.$t('Share.Invidious URL copied to clipboard')
})
this.copy(this.invidiousURLWithTime)
this.$refs.iconButton.toggleDropdown()
},
2020-06-17 13:36:44 +00:00
openYoutube() {
2020-06-18 14:53:54 +00:00
this.open(this.youtubeURL)
this.$refs.iconButton.toggleDropdown()
2020-06-17 13:36:44 +00:00
},
2020-09-11 03:48:06 +00:00
openYoutubeAtTime() {
this.open(this.youtubeURLWithTime)
this.$refs.iconButton.toggleDropdown()
},
2020-06-17 13:36:44 +00:00
copyYoutube() {
this.showToast({
message: this.$t('Share.YouTube URL copied to clipboard')
})
2020-06-18 14:53:54 +00:00
this.copy(this.youtubeURL)
this.$refs.iconButton.toggleDropdown()
2020-06-17 13:36:44 +00:00
},
2020-09-11 03:48:06 +00:00
copyYoutubeAtTime() {
this.showToast({
message: this.$t('Share.YouTube URL copied to clipboard')
})
this.copy(this.youtubeURLWithTime)
this.$refs.iconButton.toggleDropdown()
},
2020-06-17 13:36:44 +00:00
openYoutubeEmbed() {
2020-06-18 14:53:54 +00:00
this.open(this.youtubeEmbedURL)
this.$refs.iconButton.toggleDropdown()
2020-06-17 13:36:44 +00:00
},
copyYoutubeEmbed() {
this.showToast({
message: this.$t('Share.YouTube Embed URL copied to clipboard')
})
2020-06-18 14:53:54 +00:00
this.copy(this.youtubeEmbedURL)
this.$refs.iconButton.toggleDropdown()
2020-06-17 13:58:06 +00:00
},
openInvidiousEmbed() {
2020-06-18 14:53:54 +00:00
this.open(this.invidiousEmbedURL)
this.$refs.iconButton.toggleDropdown()
2020-06-17 13:58:06 +00:00
},
copyInvidiousEmbed() {
this.showToast({
message: this.$t('Share.Invidious Embed URL copied to clipboard')
})
2020-06-18 14:53:54 +00:00
this.copy(this.invidiousEmbedURL)
this.$refs.iconButton.toggleDropdown()
2020-06-17 13:58:06 +00:00
},
2020-07-04 15:44:35 +00:00
...mapActions([
'showToast'
])
2020-06-17 12:15:36 +00:00
}
})