X-Git-Url: https://git.ktnx.net/?p=icedeb.git;a=blobdiff_plain;f=icedeb.js;h=41117778fa9a08fc08acb30ff44b05acb69b465b;hp=29327a85166cc6df8d45d018bf7421f6a4be7b20;hb=c28c4dad3eb96d8ad3a01ea68aa1c29c4fbddce9;hpb=7c295465c545334178efd5b6647a75ca3052dff8 diff --git a/icedeb.js b/icedeb.js index 29327a8..4111777 100644 --- a/icedeb.js +++ b/icedeb.js @@ -204,17 +204,29 @@ function check_likely_inputs(q) { } ); } -function get_clipboard_contents() { - let clip_pot = document.getElementById('clip-pot'); +function react_to_clipboard_text(text) { let clip_input = document.getElementById("clipboard"); - clip_pot.focus(); - if (document.execCommand("Paste")) { - let q = clip_pot.textContent.trim(); - clip_input.value = q; - clip_input.focus(); - clip_input.setSelectionRange(0, clip_input.value.length); - - check_likely_inputs(q); + clip_input.value = text; + clip_input.focus(); + clip_input.setSelectionRange(0, clip_input.value.length); + + check_likely_inputs(text); +} + +function get_clipboard_contents() { + if (navigator.clipboard && navigator.clipboard.readText) { + navigator.clipboard.readText().then(function(q){ + react_to_clipboard_text(q); + }); + } + else { + let clip_pot = document.getElementById('clip-pot'); + let clip_input = document.getElementById("clipboard"); + clip_pot.focus(); + if (document.execCommand("Paste")) { + let q = clip_pot.textContent.trim(); + react_to_clipboard_text(q); + } } } @@ -240,3 +252,5 @@ window.addEventListener('DOMContentLoaded', (e) => { window.requestAnimationFrame(get_clipboard_contents); }); }); + +// vim: sw=2