From 11c055c006bdb91316309563251d91981439cf33 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 19 Jun 2017 12:35:03 +0000 Subject: [PATCH] put clipboard retrieval in a routine, hook to DOMContentLoaded --- icedeb.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/icedeb.js b/icedeb.js index 30f4c3e..338f292 100644 --- a/icedeb.js +++ b/icedeb.js @@ -117,11 +117,11 @@ function link_clicked(e) { } let clip_input = document.getElementById("clipboard"); - if(clip_input.value == '') + if(clip_input.textContent == '') get_clipboard_contents(); - let clip = trim(clip_input.value); + let clip = trim(clip_input.textContent); - if(clip_input.value == '') return; + if(clip_input.textContent == '') return; let url; @@ -161,15 +161,12 @@ function link_clicked(e) { } }); -window.addEventListener('load', (e) => { - document.getElementById('button-list-container').addEventListener('click', link_clicked); + e.preventDefault(); + return false; +} - document.addEventListener('change', (e) => { - if ( !e.target.classList.contains('icedeb-option') ) - return; - - save_settings(); - }); +function get_clipboard_contents() { + document.getElementById('error').classList.add('hidden'); let clip_input = document.getElementById("clipboard"); clip_input.focus(); @@ -178,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(); }); -- 2.39.5