Fix fullscreen copy

It seems we can't copy element outside the fullscreen element
This commit is contained in:
Chocobozzz 2024-10-07 09:34:32 +02:00
parent 5f886402f5
commit d96bc49742
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 11 additions and 9 deletions

View File

@ -502,7 +502,7 @@ export class PeerTubePlayer {
{ {
label: player.localize('Copy the video URL'), label: player.localize('Copy the video URL'),
listener: function () { listener: function () {
copyToClipboard(buildVideoLink({ shortUUID })) copyToClipboard(buildVideoLink({ shortUUID }), player.el() as HTMLElement)
} }
}, },
{ {
@ -510,17 +510,17 @@ export class PeerTubePlayer {
listener: function () { listener: function () {
const url = buildVideoLink({ shortUUID }) const url = buildVideoLink({ shortUUID })
copyToClipboard(decorateVideoLink({ url, startTime: player.currentTime() })) copyToClipboard(decorateVideoLink({ url, startTime: player.currentTime() }), player.el() as HTMLElement)
} }
}, },
{ {
icon: 'code', icon: 'code',
label: player.localize('Copy embed code'), label: player.localize('Copy embed code'),
listener: () => { listener: () => {
copyToClipboard(buildVideoOrPlaylistEmbed({ copyToClipboard(
embedUrl: self.currentLoadOptions.embedUrl, buildVideoOrPlaylistEmbed({ embedUrl: self.currentLoadOptions.embedUrl, embedTitle: self.currentLoadOptions.embedTitle }),
embedTitle: self.currentLoadOptions.embedTitle player.el() as HTMLElement
})) )
} }
} }
] ]

View File

@ -1,13 +1,15 @@
function copyToClipboard (text: string) { function copyToClipboard (text: string, container?: HTMLElement) {
if (!container) container = document.body
const el = document.createElement('textarea') const el = document.createElement('textarea')
el.value = text el.value = text
el.setAttribute('readonly', '') el.setAttribute('readonly', '')
el.style.position = 'absolute' el.style.position = 'absolute'
el.style.left = '-9999px' el.style.left = '-9999px'
document.body.appendChild(el) container.appendChild(el)
el.select() el.select()
document.execCommand('copy') document.execCommand('copy')
document.body.removeChild(el) container.removeChild(el)
} }
function wait (ms: number) { function wait (ms: number) {