diff options
| author | Shishkevich D. <135337715+shishkevichd@users.noreply.github.com> | 2025-03-07 10:27:33 +0300 |
|---|---|---|
| committer | Shishkevich D. <135337715+shishkevichd@users.noreply.github.com> | 2025-03-07 10:27:33 +0300 |
| commit | 26bf693dbdc2db0222ee37615e353f7ca1fdd3c1 (patch) | |
| tree | e5ad1ba0a99242049934892062db0d1762f0de1a /web/assets/js/util/utils.js | |
| parent | 7483fb2ec57055f5f4f0fb14e559a87a5c2106f9 (diff) | |
refactor: move copy function to utils.js
Diffstat (limited to 'web/assets/js/util/utils.js')
| -rw-r--r-- | web/assets/js/util/utils.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js index a79ce3a0..ab7c977a 100644 --- a/web/assets/js/util/utils.js +++ b/web/assets/js/util/utils.js @@ -480,6 +480,38 @@ class Wireguard { } } +class ClipboardManager { + static copyText(content = "") { + // !! here old way of copying is used because not everyone can afford https connection + return new Promise((resolve) => { + try { + const textarea = window.document.createElement('textarea'); + + textarea.style.fontSize = '12pt'; + textarea.style.border = '0'; + textarea.style.padding = '0'; + textarea.style.margin = '0'; + textarea.style.position = 'absolute'; + textarea.style.left = '-9999px'; + textarea.style.top = `${window.pageYOffset || document.documentElement.scrollTop}px`; + textarea.setAttribute('readonly', ''); + textarea.value = content; + + window.document.body.appendChild(textarea); + + textarea.select(); + window.document.execCommand("copy"); + + window.document.body.removeChild(textarea); + + resolve(true) + } catch { + resolve(false) + } + }) + } +} + class Base64 { static encode(content = "", safe = false) { if (safe) { |
