X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;ds=sidebyside;f=icedeb.js;h=175fdf1c5ec443ee6c66657a77cf0371487a79ad;hb=06e6c49f57bae8c75edb986406e9f99933676b4a;hp=30f4c3e4739aa495de1e6cb53e7a97c1b1f93bf5;hpb=35a72bd219624257632d7bfafb586ba9b32d067f;p=icedeb.git diff --git a/icedeb.js b/icedeb.js index 30f4c3e..175fdf1 100644 --- a/icedeb.js +++ b/icedeb.js @@ -117,8 +117,6 @@ function link_clicked(e) { } let clip_input = document.getElementById("clipboard"); - if(clip_input.value == '') - get_clipboard_contents(); let clip = trim(clip_input.value); if(clip_input.value == '') return; @@ -161,8 +159,26 @@ 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() { + let clip_pot = document.getElementById('clip-pot'); + let clip_input = document.getElementById("clipboard"); + clip_pot.focus(); + if (document.execCommand("Paste")) { + 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') ) @@ -171,11 +187,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); + }); });