diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 5c717ca..ceda5c4 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,29 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/web/v2/js/paste.js b/web/v2/js/paste.js index 7f9b9df..07d4394 100644 --- a/web/v2/js/paste.js +++ b/web/v2/js/paste.js @@ -36,6 +36,8 @@ let paste_modal = { qrcode: null, title: null, expired: null, + id_copy_btn: null, + id_copy_btn_icon: null, }; let saved_modal = null; @@ -80,10 +82,17 @@ function build_paste_modal(paste_info, show_qrcode = true, saved = true) { return; } + let tooltip = bootstrap.Tooltip.getInstance(paste_modal.id_copy_btn); + paste_modal.uuid.text(paste_info.link); paste_modal.uuid.prop('href', paste_info.link); paste_modal.qrcode.prop('src', paste_info.link_qr); paste_modal.qrcode.prop('alt', paste_info.link); + paste_modal.id_copy_btn_icon.addClass('bi-clipboard'); + paste_modal.id_copy_btn_icon.removeClass('bi-check2'); + paste_modal.id_copy_btn.addClass('btn-primary'); + paste_modal.id_copy_btn.removeClass('btn-success'); + tooltip.setContent({'.tooltip-inner': 'Click to copy'}); // Hide/Show QRCode if (!show_qrcode) paste_modal.qrcode.addClass('d-none'); @@ -108,6 +117,8 @@ $(function () { paste_modal.modal = $('#paste_modal'); paste_modal.uuid = $('#paste_uuid'); paste_modal.qrcode = $('#paste_qrcode'); + paste_modal.id_copy_btn = $('#id_copy_button'); + paste_modal.id_copy_btn_icon = $('#id_copy_button_icon'); let file_stat = $('#file_stats'); let title = $('#paste_title'); @@ -287,6 +298,26 @@ $(function () { } }); + paste_modal.id_copy_btn.on('click', async function () { + const uuid = paste_modal.uuid.text(); + let tooltip = bootstrap.Tooltip.getInstance(paste_modal.id_copy_btn); + + if (navigator.clipboard) { + try { + await navigator.clipboard.writeText(uuid); + paste_modal.id_copy_btn_icon.removeClass('bi-clipboard'); + paste_modal.id_copy_btn_icon.addClass('bi-check2'); + paste_modal.id_copy_btn.removeClass('btn-primary'); + paste_modal.id_copy_btn.addClass('btn-success'); + tooltip.setContent({'.tooltip-inner': 'Copied'}); + } catch (err) { + tooltip.setContent({'.tooltip-inner': 'Copied failed'}); + } + } else { + tooltip.setContent({'.tooltip-inner': 'Copied failed'}); + } + }); + }); function select_input_type(name) { diff --git a/web/v2/paste.html b/web/v2/paste.html index 232cd70..6cce5b0 100644 --- a/web/v2/paste.html +++ b/web/v2/paste.html @@ -168,20 +168,27 @@