X-Git-Url: https://git.ktnx.net/?p=icedeb.git;a=blobdiff_plain;f=icedeb.js;h=9c9a77053aa597e6b418f69d5efd6c2306a92eb6;hp=c36044c7c6d3a4d75c29cb3cc37f218aaa25f21e;hb=aee59ae1e856b0f51f4806fdadfdb6ecda01609e;hpb=f58a4234607ccc574ea15773b26c7fec6eb259d7 diff --git a/icedeb.js b/icedeb.js index c36044c..9c9a770 100644 --- a/icedeb.js +++ b/icedeb.js @@ -116,15 +116,12 @@ function link_clicked(e) { return false; } - if ( !e.target.classList.contains('icedeb-button') ) - return; - - let autoclose = true; - let clip_input = document.getElementById("clipboard"); + if(clip_input.value == '') + get_clipboard_contents(); let clip = trim(clip_input.value); - console.log(clip); + if(clip_input.value == '') return; let url; @@ -164,8 +161,33 @@ function link_clicked(e) { } }); -window.addEventListener('load', (e) => { - document.getElementById('button-list-container').addEventListener('click', link_clicked); + e.preventDefault(); + return false; +} + +function get_clipboard_contents() { + document.getElementById('error').classList.add('hidden'); + + let clip_pot = document.getElementById('clip-pot'); + let clip_input = document.getElementById("clipboard"); + clip_pot.focus(); + if (!document.execCommand("Paste")) { + let err = document.getElementById('error'); + err.textContent = 'Error retrieving clipboard contents'; + err.classList.remove('hidden'); + } + else { + clip_input.value = clip_pot.textContent.trim(); + clip_input.focus(); + clip_input.setSelectionRange(0, clip_input.value.length) + } +} + +window.addEventListener('DOMContentLoaded', (e) => { + document.querySelectorAll('.icedeb-button, #button-list-container a') + .forEach(function(el){ + el.addEventListener('mouseup', link_clicked); + }); document.addEventListener('change', (e) => { if ( !e.target.classList.contains('icedeb-option') ) @@ -174,11 +196,7 @@ window.addEventListener('load', (e) => { save_settings(); }); - let clip_input = document.getElementById("clipboard"); - clip_input.focus(); - if (!document.execCommand("paste")) { - let err = document.getElementById('error'); - err.textContent = 'Error retrieving clipboard contents'; - err.classList.remove('hidden'); - } + window.requestAnimationFrame(()=>{ + window.requestAnimationFrame(get_clipboard_contents); + }); });