X-Git-Url: https://git.ktnx.net/?p=icedeb.git;a=blobdiff_plain;f=icedeb.js;h=338f292691466a8fdc677b6c63fd172ce849504f;hp=c36044c7c6d3a4d75c29cb3cc37f218aaa25f21e;hb=a616d47af8df39cffe632272af83772d904d5cbf;hpb=f58a4234607ccc574ea15773b26c7fec6eb259d7 diff --git a/icedeb.js b/icedeb.js index c36044c..338f292 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"); - let clip = trim(clip_input.value); + if(clip_input.textContent == '') + get_clipboard_contents(); + let clip = trim(clip_input.textContent); - console.log(clip); + if(clip_input.textContent == '') return; let url; @@ -164,15 +161,12 @@ function link_clicked(e) { } }); -window.addEventListener('load', (e) => { - document.getElementById('button-list-container').addEventListener('click', link_clicked); - - document.addEventListener('change', (e) => { - if ( !e.target.classList.contains('icedeb-option') ) - return; + e.preventDefault(); + return false; +} - save_settings(); - }); +function get_clipboard_contents() { + document.getElementById('error').classList.add('hidden'); let clip_input = document.getElementById("clipboard"); clip_input.focus(); @@ -181,4 +175,20 @@ window.addEventListener('load', (e) => { err.textContent = 'Error retrieving clipboard contents'; err.classList.remove('hidden'); } +} + +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') ) + return; + + save_settings(); + }); + + get_clipboard_contents(); });