Skip to content

Commit

Permalink
Fix paste button сurl command chao#354
Browse files Browse the repository at this point in the history
- Add new way to read clipboard content
  • Loading branch information
Vasilii Grigorev committed Aug 30, 2023
1 parent de79b7d commit 252d4a3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/scripts/cores/curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 252d4a3

Please sign in to comment.