Load external script

7 views
Skip to first unread message

Giustino Borzacchiello

unread,
Nov 20, 2009, 1:32:07 PM11/20/09
to mozilla-labs-jetpack
Hi, I'm trying to make a jetpack feature for the social network Meemi
(meemi.com) .
I need to send an encrypted password to the API, so i have to include
all the functions for SHA256.
Can I store this functions in an external file, and get it from the
jetpack code?
I've read about the $.getScript method, but it seems it doesn't work.
Can someone hint me?

Aza

unread,
Nov 20, 2009, 8:15:05 PM11/20/09
to mozilla-la...@googlegroups.com
Hi Guistino,

Unfortunately, at the moment there is no good way of doing this. The two methods you can use are:

(1) Use a statusBar panel to host an HTML file, and then inject the code in there (which you can then access from your main script)
(2) Use .get() to get the code and then eval it.

Both are ugly, but we are working on a better solution which should be ready soon — a full library system for Jetpack.

-- aza | ɐzɐ --



--

You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
To post to this group, send email to mozilla-la...@googlegroups.com.
To unsubscribe from this group, send email to mozilla-labs-jet...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mozilla-labs-jetpack?hl=.



Giustino Borzacchiello

unread,
Nov 21, 2009, 3:02:13 AM11/21/09
to mozilla-labs-jetpack
Thanks for the reply :)

On Nov 21, 2:15 am, Aza <aza...@gmail.com> wrote:
> Hi Guistino,
>
> Unfortunately, at the moment there is no good way of doing this. The two
> methods you can use are:
>
> (1)
> Use a statusBar panel to host an HTML file, and then inject the code
> in there (which you can then access from your main script)
> (2) Use .get() to get the code and then eval it.
>
> Both are ugly, but we are working on a better solution which should be
> ready soon — a full library system for Jetpack.
>
> -- aza | ɐzɐ --
>
> On Fri, Nov 20, 2009 at 10:32 AM, Giustino Borzacchiello <
>
> giusti...@gmail.com> wrote:
> > Hi, I'm trying to make a jetpack feature for the social network Meemi
> > (meemi.com) .
> > I need to send an encrypted password to the API, so i have to include
> > all the functions for SHA256.
> > Can I store this functions in an external file, and get it from the
> > jetpack code?
> > I've read about the $.getScript method, but it seems it doesn't work.
> > Can someone hint me?
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "mozilla-labs-jetpack" group.
> > To post to this group, send email to mozilla-la...@googlegroups.com
> > .
> > To unsubscribe from this group, send email to
> > mozilla-labs-jet...@googlegroups.com<mozilla-labs-jetpack%2Bunsu...@googlegroups.com>
> > .

Backpack

unread,
Nov 22, 2009, 12:18:54 PM11/22/09
to mozilla-labs-jetpack
What I've done is to create a 'script' tag and inject it to the main
document setting the 'src' attribute to the file you need.

----
var doc,head,script;

doc = jetpack.tabs.focused.contentDocument;
head = doc.querySelector('head');

script = doc.createElement('SCRIPT');
script.type = 'text/javascript';
script.src = 'http://example.com/yourscript.js';
head.appendChild(script);
----

HTH

mcepl

unread,
Jan 11, 2010, 6:40:58 PM1/11/10
to mozilla-labs-jetpack
On Nov 22 2009, 6:18 pm, Backpack <georgen...@gmail.com> wrote:
> ----
>     var doc,head,script;
>
>     doc  = jetpack.tabs.focused.contentDocument;
>     head = doc.querySelector('head');
>
>     script      = doc.createElement('SCRIPT');
>     script.type = 'text/javascript';
>     script.src  = 'http://example.com/yourscript.js';
>     head.appendChild(script);
> ----

Just to anybody who would be as lost as I was where actually the
script is, this is more complete example (it's better to use
script.innerHTML in XMLHTTPRequest instead of script.scr, because then
we don't have to deal with waiting on loading of the script, and we
can be sure, that it is already loaded):

var XMLRPCMessage = {};
var req = new XMLHttpRequest();
req.open("GET","http://mcepl.fedorapeople.org/scripts/
xmlrpc.js",true);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if (req.status == 200) {
var thisDoc = jetpack.tabs.focused.contentDocument;
var script = thisDoc.createElement("script");
script.setAttribute("type","text/javascript");
script.innerHTML = req.responseText;
thisDoc.getElementsByTagName("head")[0].appendChild
(script);
XMLRPCMessage =
jetpack.tabs.focused.contentWindow.wrappedJSObject.XMLRPCMessage;
}
}
};
req.send("");

(of course, $.get() can be used instead, but I prefer plain Javascript
to jQuery)

Reply all
Reply to author
Forward
0 new messages