]> git.ktnx.net Git - icedeb.git/blob - chrome/icedeb.js
66159cff2e222a782dd54c4d57dcdf0bf6799adb
[icedeb.git] / chrome / icedeb.js
1 function getClipboardText() {
2     var clip = Components.classes['@mozilla.org/widget/clipboard;1']
3         .getService(Components.interfaces.nsIClipboard);
4     if (!clip) return null;
5
6     var trans = Components.classes['@mozilla.org/widget/transferable;1']
7         .createInstance(Components.interfaces.nsITransferable);
8     if (!trans) return null;
9
10     trans.addDataFlavor("text/unicode");
11     clip.getData(trans,
12             clip.supportsSelectionClipboard()
13             ? clip.kSelectionClipboard
14             : clip.kGlobalClipboard
15     );
16
17     var str = new Object;
18     var strLength = new Object;
19     trans.getTransferData("text/unicode", str, strLength);
20
21     var text = null;
22
23     if (str) str  = str.value.QueryInterface(Components.interfaces.nsISupportsString);
24     if (str) text = str.data.substring(0, strLength.value / 2);
25
26     return text;
27 }
28
29 function lookup_bts(in_new) {
30     var bug = getClipboardText();
31     if (!bug) return null;
32     bug = bug.replace(/^#/, '');
33     var uri="http://bugs.debian.org/" + bug;
34
35     if (in_new) {
36         var b = getBrowser();
37         var new_tab = b.addTab(uri);
38         b.selectedTab = new_tab;
39     }
40     else {
41         loadURI(uri);
42     }
43 }
44
45 function lookup_pts(in_new) {
46     var pkg = getClipboardText();
47     if (!pkg) return null;
48     var uri="http://packages.qa.debian.org/" + pkg;
49
50     if (in_new) {
51         var b = getBrowser();
52         var new_tab = b.addTab(uri);
53         b.selectedTab = new_tab;
54     }
55     else {
56         loadURI(uri);
57     }
58 }
59
60 Debian = {
61     btsButton: function (e) {
62         if ( e.button == 0 )
63             lookup_bts(false)
64         else if ( e.button == 1 )
65             lookup_bts(true);
66     },
67     ptsButton: function (e) {
68         if ( e.button == 0 )
69             lookup_pts(false)
70         else if ( e.button == 1 )
71             lookup_pts(true);
72     }
73 }
74