--- /dev/null
+function load_settings() {
+ browser.storage.local.get({auto_close: true})
+ .then(
+ function(v) {
+ document.getElementById('auto-close').checked = v.auto_close === true;
+ //console.log('Success', v);
+ },
+ function() {
+ document.getElementById('auto-close').checked = true;
+ //console.log('Failure');
+ }
+ );
+}
+
+function save_settings() {
+ let v = document.getElementById('auto-close').checked;
+ browser.storage.local.set({
+ auto_close: v,
+ });
+ //console.log('stored', v);
+}
+
+function trim(word) {
+ if (!word) return word;
+
+ var oldword;
+ do {
+ oldword = word;
+
+ word = word.replace(/^[^a-zA-Z0-9]+/, '');
+ word = word.replace(/[^a-zA-Z0-9]+$/, '');
+ word = word.replace(/^Bug#/i, '');
+ } while ( oldword != word );
+
+ return word;
+}
+
+function open_tab(url) {
+ browser.tabs.create({url:url})
+ .then(
+ function() {},
+ function(err) {
+ console.log('Error creating tab', err);
+ }
+ );
+}
+
+document.addEventListener('click', (e) => {
+ console.log(e.button);
+ 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.textContent);
+
+ let url;
+
+ switch (e.target.id) {
+ case 'bts':
+ url = 'https://bugs.debian.org/' + clip;
+ break;
+ case 'pts':
+ url = 'https://tracker.debian.org/' + clip;
+ break;
+ case 'deb':
+ url = 'https://packages.debian.org/' + clip;
+ break;
+ case 'ml':
+ url = 'https://lists.debian.org/msgid-search/' + clip;
+ break;
+ case 'ddpo':
+ url = 'https://qa.debian.org/developer.php';
+ if (clip != '')
+ url += '?login=' + clip;
+ break;
+ case 'buildd':
+ url = 'https://buildd.debian.org/' + clip;
+ break;
+ case 'security':
+ url = 'https://security-tracker.debian.org/';
+ if (clip != '')
+ url += 'tracker/' + clip;
+ break;
+ }
+
+ if (e.button == 1) {
+ open_tab(url);
+ if (autoclose) window.close();
+ 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} );
+ if (autoclose) window.close();
+ },
+ 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);
+ if (autoclose) window.close();
+ }
+ );
+});
+
+document.addEventListener('change', (e) => {
+ if ( !e.target.classList.contains('icedeb-option') )
+ return;
+
+ save_settings();
+});
+
+browser.runtime.getPlatformInfo()
+ .then(function(info) {
+ console.log(info.os);
+
+ switch (info.os) {
+ case 'linux':
+ case 'openbsd':
+ document.getElementById('sorry').classList.remove('hidden');
+ break;
+ }
+ });