Skip to content

Allow reading curl command from clipboard on initial load #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ <h2 class="mb-sm-0">curl command</h2>
<a id="basic-auth-example" href="#">Basic Auth</a>
</small>
</div>
<div class="col-12 order-2 order-sm-3 pb-sm-3">
<div class="col-12 order-2 order-sm-3">
<textarea id="curl-code" class="form-control" placeholder="curl example.com" rows=6 autofocus spellcheck="false" autocorrect="off" autocapitalize="none"></textarea>
</div>
<div class="d-none d-xl-flex flex-row-reverse order-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="autoPaste">
<label class="form-check-label" for="flexCheckDefault">
Auto paste
</label>
</div>
</div>
</div>

<div class="row pb-1 pb-lg-0" role="navigation">
Expand Down
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()