]> git.ktnx.net Git - icedeb.git/blobdiff - icedeb.js
nicer popup, site links, remove text about absent selection-clipboard support
[icedeb.git] / icedeb.js
index dcd1197506839e86cebcd3920cb37f021f2a0fb2..8c2a7e66080d64372bb16f47933583f70fb6b05b 100644 (file)
--- 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;
-    }
-  });