]> git.ktnx.net Git - icedeb.git/blob - icedeb.js
initial implementation of e10s. XUL/XPCOM is dropped
[icedeb.git] / icedeb.js
1 function load_settings() {
2   browser.storage.local.get({auto_close: true})
3   .then(
4     function(v) {
5       document.getElementById('auto-close').checked = v.auto_close === true;
6       //console.log('Success', v);
7     },
8     function() {
9       document.getElementById('auto-close').checked = true;
10       //console.log('Failure');
11     }
12   );
13 }
14
15 function save_settings() {
16   let v = document.getElementById('auto-close').checked;
17   browser.storage.local.set({
18     auto_close: v,
19   });
20   //console.log('stored', v);
21 }
22
23 function trim(word) {
24   if (!word) return word;
25
26   var oldword;
27   do {
28     oldword = word;
29
30     word = word.replace(/^[^a-zA-Z0-9]+/, '');
31     word = word.replace(/[^a-zA-Z0-9]+$/, '');
32     word = word.replace(/^Bug#/i, '');
33   } while ( oldword != word );
34
35   return word;
36 }
37
38 function open_tab(url) {
39   browser.tabs.create({url:url})
40     .then(
41       function() {},
42       function(err) {
43         console.log('Error creating tab', err);
44       }
45     );
46 }
47
48 document.addEventListener('click', (e) => {
49   console.log(e.button);
50   if ( !e.target.classList.contains('icedeb-button') )
51     return;
52
53   let autoclose = true;
54
55   let clip_input = document.getElementById("clipboard");
56   clip_input.focus();
57   if (!document.execCommand("paste")) {
58     let err = document.getElementById('error');
59     err.textContent = 'Error executing Paste';
60     err.classList.remove('hidden');
61     return;
62   }
63
64   let clip = trim(clip_input.textContent);
65
66   let url;
67
68   switch (e.target.id) {
69     case 'bts':
70       url = 'https://bugs.debian.org/' + clip;
71       break;
72     case 'pts':
73       url = 'https://tracker.debian.org/' + clip;
74       break;
75     case 'deb':
76       url = 'https://packages.debian.org/' + clip;
77       break;
78     case 'ml':
79       url = 'https://lists.debian.org/msgid-search/' + clip;
80       break;
81     case 'ddpo':
82       url = 'https://qa.debian.org/developer.php';
83       if (clip != '')
84         url += '?login=' + clip;
85       break;
86     case 'buildd':
87       url = 'https://buildd.debian.org/' + clip;
88       break;
89     case 'security':
90       url = 'https://security-tracker.debian.org/';
91       if (clip != '')
92         url += 'tracker/' + clip;
93       break;
94   }
95
96   if (e.button == 1) {
97     open_tab(url);
98     if (autoclose) window.close();
99     return;
100   }
101
102   browser.tabs.query({active:true, currentWindow:true})
103     .then(
104       function(tabs) {
105         browser.tabs.executeScript(tabs[0].id, {file: '/icedeb-content.js'})
106           .then(
107             function(){
108               browser.tabs.sendMessage( tabs[0].id, {url:url} );
109               if (autoclose) window.close();
110             },
111             function(err){
112               console.log('Error executing script', err);
113             });
114
115       },
116       function(err) {
117         console.log('Error querying the active tab of the current window', err);
118         open_tab(url);
119         if (autoclose) window.close();
120       }
121     );
122 });
123
124 document.addEventListener('change', (e) => {
125   if ( !e.target.classList.contains('icedeb-option') )
126     return;
127
128   save_settings();
129 });
130
131 browser.runtime.getPlatformInfo()
132   .then(function(info) {
133     console.log(info.os);
134
135     switch (info.os) {
136       case 'linux':
137       case 'openbsd':
138         document.getElementById('sorry').classList.remove('hidden');
139         break;
140     }
141   });