X-Git-Url: https://git.ktnx.net/?p=icedeb.git;a=blobdiff_plain;f=icedeb.js;h=902ba3bbb1826aac46eff8b9be676b3aa8e12c60;hp=29327a85166cc6df8d45d018bf7421f6a4be7b20;hb=d28e9ea2cafd33cb88729025f07d5f542b0af5fb;hpb=7c295465c545334178efd5b6647a75ca3052dff8 diff --git a/icedeb.js b/icedeb.js index 29327a8..902ba3b 100644 --- a/icedeb.js +++ b/icedeb.js @@ -204,17 +204,28 @@ function check_likely_inputs(q) { } ); } +function react_to_clipboard_text(text) { + clip_input.value = text; + clip_input.focus(); + clip_input.setSelectionRange(0, clip_input.value.length); + + check_likely_inputs(text); +} + function get_clipboard_contents() { - 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(); - clip_input.value = q; - clip_input.focus(); - clip_input.setSelectionRange(0, clip_input.value.length); - - check_likely_inputs(q); + 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 +251,5 @@ window.addEventListener('DOMContentLoaded', (e) => { window.requestAnimationFrame(get_clipboard_contents); }); }); + +// vim: sw=2