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

138 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-06-17 12:15:36 +00:00
import Vue from 'vue'
2020-09-12 03:20:26 +00:00
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
2020-06-17 12:15:36 +00:00
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import FtButton from '../ft-button/ft-button.vue'
2020-09-12 03:20:26 +00:00
import FtToggleSwitch from '../ft-toggle-switch/ft-toggle-switch.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: {
2020-09-12 03:20:26 +00:00
'ft-flex-box': FtFlexBox,
2020-06-17 12:15:36 +00:00
'ft-icon-button': FtIconButton,
2020-09-12 03:20:26 +00:00
'ft-button': FtButton,
'ft-toggle-switch': FtToggleSwitch
2020-06-17 13:36:44 +00:00
},
props: {
id: {
type: String,
required: true
2020-09-11 03:48:06 +00:00
},
2020-09-12 03:20:26 +00:00
getTimestamp: {
type: Function,
required: true
}
},
data: function () {
return {
includeTimestamp: false
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-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}`
},
youtubeShareURL() {
return `https://youtu.be/${this.id}`
},
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-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-09-12 03:20:26 +00:00
this.open(this.getFinalUrl(this.invidiousURL))
this.$refs.iconButton.focusOut()
2020-09-11 03:48:06 +00:00
},
2020-06-17 13:36:44 +00:00
copyInvidious() {
this.showToast({
message: this.$t('Share.Invidious URL copied to clipboard')
})
2020-09-12 03:20:26 +00:00
this.copy(this.getFinalUrl(this.invidiousURL))
this.$refs.iconButton.focusOut()
2020-09-11 03:48:06 +00:00
},
2020-06-17 13:36:44 +00:00
openYoutube() {
2020-09-12 03:20:26 +00:00
this.open(this.getFinalUrl(this.youtubeURL))
this.$refs.iconButton.focusOut()
2020-09-11 03:48:06 +00:00
},
2020-06-17 13:36:44 +00: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 03:48:06 +00:00
},
2020-06-17 13:36:44 +00:00
openYoutubeEmbed() {
2020-09-12 03:20:26 +00:00
this.open(this.getFinalUrl(this.youtubeEmbedURL))
this.$refs.iconButton.focusOut()
2020-06-17 13:36:44 +00:00
},
copyYoutubeEmbed() {
this.showToast({
message: this.$t('Share.YouTube Embed URL copied to clipboard')
})
2020-09-12 03:20:26 +00:00
this.copy(this.getFinalUrl(this.youtubeEmbedURL))
this.$refs.iconButton.focusOut()
2020-06-17 13:58:06 +00:00
},
openInvidiousEmbed() {
2020-09-12 03:20:26 +00:00
this.open(this.getFinalUrl(this.invidiousEmbedURL))
this.$refs.iconButton.focusOut()
2020-06-17 13:58:06 +00:00
},
copyInvidiousEmbed() {
this.showToast({
message: this.$t('Share.Invidious Embed URL copied to clipboard')
})
2020-09-12 03:20:26 +00:00
this.copy(this.getFinalUrl(this.invidiousEmbedURL))
this.$refs.iconButton.focusOut()
2020-06-17 13:58:06 +00:00
},
2020-07-04 15:44:35 +00:00
updateincludeTimestamp() {
this.includeTimestamp = !this.includeTimestamp
2020-09-12 03:20:26 +00:00
},
getFinalUrl(url) {
return this.includeTimestamp ? `${url}&t=${this.getTimestamp()}` : url
2020-09-12 03:20:26 +00:00
},
2020-07-04 15:44:35 +00:00
...mapActions([
'showToast'
])
2020-06-17 12:15:36 +00:00
}
})