added workaround to copy arbitrary text to che clipboard
This commit is contained in:
parent
40c7ba9a0c
commit
e1a3e8b562
File diff suppressed because one or more lines are too long
@ -15,7 +15,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import Downloads from '@/utils/downloads'
|
import Downloads from '@/utils/downloads'
|
||||||
import downloadQualities from '@js/qualities'
|
import downloadQualities from '@js/qualities'
|
||||||
import { generatePath } from '@/utils/utils'
|
import { generatePath, copyToClipboard } from '@/utils/utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -55,9 +55,10 @@ export default {
|
|||||||
show: false,
|
show: false,
|
||||||
position: 3,
|
position: 3,
|
||||||
action: () => {
|
action: () => {
|
||||||
navigator.clipboard.writeText(this.generalHref).catch(err => {
|
// navigator.clipboard.writeText(this.generalHref).catch(err => {
|
||||||
console.error('Link copying failed', err)
|
// console.error('Link copying failed', err)
|
||||||
})
|
// })
|
||||||
|
copyToClipboard(this.generalHref)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
copyImageLink: {
|
copyImageLink: {
|
||||||
@ -65,9 +66,10 @@ export default {
|
|||||||
show: false,
|
show: false,
|
||||||
position: 4,
|
position: 4,
|
||||||
action: () => {
|
action: () => {
|
||||||
navigator.clipboard.writeText(this.imgSrc).catch(err => {
|
// navigator.clipboard.writeText(this.imgSrc).catch(err => {
|
||||||
console.error('Image copying failed', err)
|
// console.error('Image copying failed', err)
|
||||||
})
|
// })
|
||||||
|
copyToClipboard(this.imgSrc)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
copyDeezerLink: {
|
copyDeezerLink: {
|
||||||
@ -75,14 +77,15 @@ export default {
|
|||||||
show: false,
|
show: false,
|
||||||
position: 5,
|
position: 5,
|
||||||
action: () => {
|
action: () => {
|
||||||
navigator.clipboard.writeText(this.generalHref).catch(err => {
|
// navigator.clipboard.writeText(this.deezerHref).catch(err => {
|
||||||
console.error('Deezer link copying failed', err)
|
// console.error('Deezer link copying failed', err)
|
||||||
})
|
// })
|
||||||
|
copyToClipboard(this.deezerHref)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
paste: {
|
paste: {
|
||||||
label: this.$t('globals.paste'),
|
label: this.$t('globals.paste'),
|
||||||
show: true,
|
show: !window.clientMode,
|
||||||
position: 6,
|
position: 6,
|
||||||
action: () => {
|
action: () => {
|
||||||
navigator.clipboard.readText().then(text => {
|
navigator.clipboard.readText().then(text => {
|
||||||
|
@ -73,6 +73,24 @@ export function debounce(func, wait, immediate) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workaround to copy to the clipboard cross-OS by generating a
|
||||||
|
* ghost input and copying the passed String
|
||||||
|
*
|
||||||
|
* @param {string} text Text to copy
|
||||||
|
*/
|
||||||
|
export function copyToClipboard(text) {
|
||||||
|
const ghostInput = document.createElement('input')
|
||||||
|
|
||||||
|
document.body.appendChild(ghostInput)
|
||||||
|
ghostInput.setAttribute('type', 'text')
|
||||||
|
ghostInput.setAttribute('value', text)
|
||||||
|
ghostInput.select()
|
||||||
|
ghostInput.setSelectionRange(0, 99999)
|
||||||
|
document.execCommand('copy')
|
||||||
|
ghostInput.remove()
|
||||||
|
}
|
||||||
|
|
||||||
export const COUNTRIES = {
|
export const COUNTRIES = {
|
||||||
AF: 'Afghanistan',
|
AF: 'Afghanistan',
|
||||||
AX: '\u00c5land Islands',
|
AX: '\u00c5land Islands',
|
||||||
|
Loading…
Reference in New Issue
Block a user