blob: 8c916b2565768fe8a1e4cfbeb9d56b2146e24a9c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/*
* Copyright (C) 2024 dwlr <dweller@cabin.digital>
*
* BSD 3-Clause License (BSD-3-Clause)
* See LICENSE for details
*/
const dom_lmmtfy = document.getElementById("lmmtfy_url");
const dom_copy = document.getElementById("lmmtfy_copy");
dom_copy.onclick = lmmtfy_copy;
function lmmtfy_copy()
{
dom_lmmtfy.focus();
dom_lmmtfy.select();
try
{
// TODO: deprecated -- https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
if(document.execCommand('copy'))
dom_copy.innerHTML = "Copied!"
setTimeout(() =>
{
dom_copy.innerHTML = "Copy"
}, 3000);
}
catch(err)
{
dom_copy.innerHTML = "Error :(";
console.log('Oops, unable to copy');
}
// This unfocuses the element, but W3C decided to be funny with
// the naming.
document.activeElement.blur();
}
|