show alert when copy to clipboard not https

This commit is contained in:
Alex Turchyn
2023-07-01 17:30:41 +03:00
parent 3cceaf5cc7
commit cd42d031e4
+9 -1
View File
@@ -5,7 +5,15 @@ export default class extends HTMLElement {
this.addEventListener('click', (e) => {
e.stopPropagation()
navigator.clipboard.writeText(this.dataset.text || this.innerText.trim())
const text = this.dataset.text || this.innerText.trim()
if (navigator.clipboard) {
navigator.clipboard.writeText(text)
} else {
if (e.target.tagName !== 'INPUT') {
alert(`Clipboard not available. Make sure you're using https://\nCopy text: ${text}`)
}
}
})
}