From d28e9ea2cafd33cb88729025f07d5f542b0af5fb Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Wed, 12 Sep 2018 16:15:29 +0000 Subject: [PATCH] add support for clipboard.readText(), available in firefox 63 --- icedeb.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) 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); + } } } -- 2.39.5