From: Damyan Ivanov Date: Wed, 12 Sep 2018 16:15:29 +0000 (+0000) Subject: add support for clipboard.readText(), available in firefox 63 X-Git-Tag: 2.2~5 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=d28e9ea2cafd33cb88729025f07d5f542b0af5fb;p=icedeb.git add support for clipboard.readText(), available in firefox 63 --- diff --git a/icedeb.js b/icedeb.js index 81e5f0a..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); + } } }