From 8d9f234a2cc9eb90f3cfae0e525a733cff252437 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 26 Feb 2009 14:35:26 +0200 Subject: [PATCH] clicking on the toolbar button now loads BTS bug page --- chrome/button.js | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/chrome/button.js b/chrome/button.js index a948399..3dadd3e 100644 --- a/chrome/button.js +++ b/chrome/button.js @@ -1,8 +1,39 @@ -Debian = { +function getClipboardText() { + var clip = Components.classes['@mozilla.org/widget/clipboard;1'] + .getService(Components.interfaces.nsIClipboard); + if (!clip) return null; + + var trans = Components.classes['@mozilla.org/widget/transferable;1'] + .createInstance(Components.interfaces.nsITransferable); + if (!trans) return null; + + trans.addDataFlavor("text/unicode"); + clip.getData(trans, + clip.supportsSelectionClipboard() + ? clip.kSelectionClipboard + : clip.kGlobalClipboard + ); + + var str = new Object; + var strLength = new Object; + trans.getTransferData("text/unicode", str, strLength); + + var text = null; -btsButton: function (e) { - alert("Just testing") - }, + if (str) str = str.value.QueryInterface(Components.interfaces.nsISupportsString); + if (str) text = str.data.substring(0, strLength.value / 2); + return text; +} + +function lookup_bts() { + var bug = getClipboardText(); + loadURI("http://bugs.debian.org/" + bug); +} + +Debian = { + btsButton: function (e) { + lookup_bts(); + } } -- 2.39.5