X-Git-Url: https://git.ktnx.net/?p=icedeb.git;a=blobdiff_plain;f=icedeb.js;h=8c2a7e66080d64372bb16f47933583f70fb6b05b;hp=dcd1197506839e86cebcd3920cb37f021f2a0fb2;hb=8b4cc4bb03e6fdd909226a01d0ef3332c1256d5f;hpb=5dc3ac34880c52f61bdac672374d08b87a921051 diff --git a/icedeb.js b/icedeb.js index dcd1197..8c2a7e6 100644 --- a/icedeb.js +++ b/icedeb.js @@ -45,23 +45,48 @@ function open_tab(url) { ); } -document.addEventListener('click', (e) => { - console.log(e.button); +function open_link(url, in_new_tab) { + if (in_new_tab) { + open_tab(url); + return; + } + + browser.tabs.query({active:true, currentWindow:true}) + .then( + function(tabs) { + browser.tabs.executeScript(tabs[0].id, {file: '/icedeb-content.js'}) + .then( + function(){ + browser.tabs.sendMessage( tabs[0].id, {url:url} ); + }, + function(err){ + console.log('Error executing script', err); + }); + + }, + function(err) { + console.log('Error querying the active tab of the current window', err); + open_tab(url); + } + ); +} + +function link_clicked(e) { + if (e.target.tagName == 'a') { + open_link(e.target.href, e.button == 1); + e.preventDefault(); + return false; + } + if ( !e.target.classList.contains('icedeb-button') ) return; let autoclose = true; let clip_input = document.getElementById("clipboard"); - clip_input.focus(); - if (!document.execCommand("paste")) { - let err = document.getElementById('error'); - err.textContent = 'Error executing Paste'; - err.classList.remove('hidden'); - return; - } + let clip = trim(clip_input.value); - let clip = trim(clip_input.textContent); + console.log(clip); let url; @@ -93,49 +118,25 @@ document.addEventListener('click', (e) => { break; } - if (e.button == 1) { - open_tab(url); - if (autoclose) window.close(); - return; - } + open_link(url, e.button == 1); + if (autoclose) window.close(); +} - browser.tabs.query({active:true, currentWindow:true}) - .then( - function(tabs) { - browser.tabs.executeScript(tabs[0].id, {file: '/icedeb-content.js'}) - .then( - function(){ - browser.tabs.sendMessage( tabs[0].id, {url:url} ); - if (autoclose) window.close(); - }, - function(err){ - console.log('Error executing script', err); - }); +window.addEventListener('load', (e) => { + document.getElementById('button-list-container').addEventListener('click', link_clicked); - }, - function(err) { - console.log('Error querying the active tab of the current window', err); - open_tab(url); - if (autoclose) window.close(); - } - ); -}); + document.addEventListener('change', (e) => { + if ( !e.target.classList.contains('icedeb-option') ) + return; -document.addEventListener('change', (e) => { - if ( !e.target.classList.contains('icedeb-option') ) - return; + save_settings(); + }); - 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'); + } }); - -browser.runtime.getPlatformInfo() - .then(function(info) { - console.log(info.os); - - switch (info.os) { - case 'linux': - case 'openbsd': - document.getElementById('sorry').classList.remove('hidden'); - break; - } - });