[Greasemonkey] Dynamically loading Prototype
chris feldmann
cfeldmann at gmail.com
Wed Dec 21 13:57:52 EST 2005
On 12/21/05, Rich Manalang <rich.manalang at gmail.com> wrote:
> Hi all. I've read about the pitfalls with unsafeWindow but I wanted to get
> your opinions. I'd like to dynamically create a script reference to the
> prototype.js library on a trusted server to make use of the convenience
> functions. The questions is... is this kosher... should we distributing
> scripts that do this? From what I understand, as long as we avoid passing
> GM_* references to unsafeWindow we should be ok, right?
>
> function waitForProto() {
> // waits for the prototype lib to load before continuing with the script
> if (typeof unsafeWindow.Prototype=='undefined')
> window.setTimeout(waitForProto, 1000);
> else
> alert(unsafeWindow.Prototype.Version);
> callMyCode();
> }
> function loadProto() {
> var proto = document.createElement("script");
> proto.type = "text/javascript";
> proto.src = "http://some.trusted.server/prototype.js";
> document.getElementsByTagName("head")[0].appendChild(proto);
> waitForProto();
> }
> window.addEventListener("load", loadProto(), false);
>
>
There's code in the pipe for the next version to provide this
functionality; it's already written, actually, and you can patch
greasemonkey with it:
http://www.freegarethandrew.org/mediawiki/index.php?title=GreasemonkeyImports#Code
More information about the Greasemonkey
mailing list