From 252d4a35f3a55c59176ee812348dce4712d8762f Mon Sep 17 00:00:00 2001 From: Vasilii Grigorev Date: Wed, 30 Aug 2023 14:51:48 +0300 Subject: [PATCH] =?UTF-8?q?Fix=20paste=20button=20=D1=81url=20command=20#3?= =?UTF-8?q?54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add new way to read clipboard content --- src/scripts/cores/curl.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/scripts/cores/curl.js b/src/scripts/cores/curl.js index 777219c..8031ccb 100644 --- a/src/scripts/cores/curl.js +++ b/src/scripts/cores/curl.js @@ -45,11 +45,27 @@ $(function () { function paste() { - var pasteText = document.querySelector("#curl-paste"); + var pasteText = document.querySelector("#curl-paste"), + triggerFn = function() { + console.log('[curl.js] pasted', pasteText.textContent); + $(document).trigger('curl-command-pasted', [pasteText.textContent]); + }; + pasteText.focus(); document.execCommand("paste"); - console.log('[curl.js] pasted', pasteText.textContent); - $(document).trigger('curl-command-pasted', [pasteText.textContent]); + + if (pasteText.textContent.length > 0 || navigator.clipboard === undefined) { + triggerFn(); + return; + } + + navigator.clipboard + .readText() + .then(function(clipText) { + pasteText.innerText = clipText; + pasteText.textContent = clipText; + triggerFn(); + }); } document.querySelector("#btn-curl-paste").addEventListener("click", paste);