1 function load_settings() {
2 browser.storage.local.get({auto_close: true})
5 document.getElementById('auto-close').checked = v.auto_close === true;
6 //console.log('Success', v);
9 document.getElementById('auto-close').checked = true;
10 //console.log('Failure');
15 function save_settings() {
16 let v = document.getElementById('auto-close').checked;
17 browser.storage.local.set({
20 //console.log('stored', v);
24 if (!word) return word;
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 );
38 function open_tab(url) {
39 return new Promise((resolve, reject) => {
40 browser.tabs.create({url:url, active:false})
46 //console.log('Error creating tab', err);
53 function open_link(url, in_new_tab) {
54 //console.log('open_link', url, in_new_tab);
60 //console.log('querying active tab');
61 return new Promise((resolve, reject) => {
62 browser.tabs.query({active:true, currentWindow:true})
65 //console.log('active tab queried');
66 browser.tabs.executeScript(tabs[0].id, {file: '/icedeb-content.js'})
69 //console.log('content script executed');
70 browser.tabs.sendMessage( tabs[0].id, {url:url} )
73 //console.log('message sent');
77 console.log('error sending message', err);
83 console.log('Error executing script. Probably a system tab is active', err, tabs[0]);
86 function() { resolve(); },
87 function(err) { reject(err); } );
92 console.log('Error querying the active tab of the current window', err);
95 function() { resolve(); },
96 function(err) { reject(err) }
103 function link_clicked(e) {
104 //console.log(e.target.tagName);
105 let autoclose = true;
107 if (e.target.tagName == 'A') {
108 open_link(e.target.href, e.button == 1)
111 //console.log('closing pop-up');
119 let clip_input = document.getElementById("clipboard");
120 let clip = trim(clip_input.value);
122 if(clip_input.value == '') return;
126 switch (e.target.id) {
128 url = 'https://bugs.debian.org/' + clip;
131 url = 'https://tracker.debian.org/' + clip;
134 url = 'https://packages.debian.org/' + clip;
137 url = 'https://lists.debian.org/msgid-search/' + clip;
140 url = 'https://qa.debian.org/developer.php?login=' + clip;
143 url = 'https://udd.debian.org/dmd.cgi?email1=' + clip;
146 url = 'https://buildd.debian.org/' + clip;
149 clip = clip.replace(' ', '-');
150 clip = clip.toUpperCase();
151 url = 'https://security-tracker.debian.org/tracker/' + clip;
154 url = `https://piuparts.debian.org/sid/source/${clip.substring(0,1)}/${clip}.html`;
157 url = 'https://tests.reproducible-builds.org/debian/rb-pkg/' + clip + '.html';
161 open_link(url, e.button == 1)
164 //console.log('closing pop-up');
173 function check_likely_inputs(q) {
174 let cnt = document.getElementById('button-list-container').classList;
176 cnt.remove('like-b', 'like-p', 'like-m', 'like-i');
177 document.querySelectorAll('.likely')
179 el.classList.remove('likely');
182 if ( /^\d+$/.test(q) || /^CVE-/.test(q) )
185 if ( /^[a-z0-9][a-z0-9\-+.]+$/.test(q) )
188 if ( /.@[a-z0-9-]/i.test(q) )
191 if ( /^<.+@.+>$/.test(q) )
194 document.querySelectorAll('.like-b .hint.b, .like-p .hint.p, .like-m .hint.m, .like-i .hint.i')
196 el.parentElement.parentElement.classList.add('likely');
200 function get_clipboard_contents() {
201 let clip_pot = document.getElementById('clip-pot');
202 let clip_input = document.getElementById("clipboard");
204 if (document.execCommand("Paste")) {
205 let q = clip_pot.textContent.trim();
206 clip_input.value = q;
208 clip_input.setSelectionRange(0, clip_input.value.length);
210 check_likely_inputs(q);
214 window.addEventListener('DOMContentLoaded', (e) => {
215 document.querySelectorAll('.icedeb-button, #button-list-container a')
216 .forEach(function(el){
217 el.addEventListener('mouseup', link_clicked);
220 document.querySelector('#clipboard')
221 .addEventListener('input', function(ev) {
222 check_likely_inputs(ev.target.value);
225 document.addEventListener('change', (e) => {
226 if ( !e.target.classList.contains('icedeb-option') )
232 window.requestAnimationFrame(()=>{
233 window.requestAnimationFrame(get_clipboard_contents);