From a171debc483d762edf90913cbd18ee913efdc155 Mon Sep 17 00:00:00 2001 From: Boris Verkhovskiy Date: Thu, 11 Aug 2022 22:28:40 -0700 Subject: [PATCH 1/2] Read curl command from clipboard on initial load --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index 1a07893..f3c840b 100644 --- a/index.js +++ b/index.js @@ -402,6 +402,22 @@ if (prevCommand) { if (!curlCode.value) { curlCode.value = prevCommand; } +} else { + try { + const permission = await navigator.permissions.query({ name: 'clipboard-read' }) + if (permission.state !== 'denied') { + const clipboardContents = await navigator.clipboard.readText() + if (clipboardContents.trim().startsWith('curl ')) { + const curlCode = document.getElementById('curl-code') + if (!curlCode.value) { + curlCode.value = clipboardContents; + // TODO: clipboard.writeText() too? + } + } + } + } catch (error) { + console.error("Couldn't read curl command from clipboard:", error.message); + } } convert() showInstructions() From eadaca1d5d44e00cc4b33c04f181bdeeb0e0825f Mon Sep 17 00:00:00 2001 From: Boris Verkhovskiy Date: Thu, 11 Aug 2022 22:52:32 -0700 Subject: [PATCH 2/2] Make user enable reading from clipboard first otherwise this adds an un-necessary click in a confirmation dialog to first-time users --- index.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 7aa8569..634dad1 100644 --- a/index.html +++ b/index.html @@ -55,9 +55,17 @@

curl command

Basic Auth -
+
+
+
+ + +
+