[Greasemonkey] Installing a user script via a data: url

Aaron Boodman zboogs at gmail.com
Thu Apr 7 21:57:29 EDT 2005


Julien,

Why is it that you want to encode your scripts?

On Mar 30, 2005 1:05 PM, Julien Couvreur <julien.couvreur at gmail.com> wrote:
> I'm writing a little page that allows me to generate user scripts.
> 
> For example, you specify "<a href="@@HREF">new link</a>" and a trigger
> pattern (say ".mp3" or ".torrent") and a link gets added using this
> stencil (with @@HREF replaced by the link's actually href) after the
> links in the page that match that trigger. See a generated url at the
> bottom of the page.
> 
> Anyways, the result is outputted as a "data:text/javascript,..." link.
> My problem is that when I click on that data: link, the user script
> does get displayed correctly, but GreaseMonkey doesn't recognize it as
> a user script.
> I guess it's because it's not an http url, with a file name ending in .user.js.
> 
> How could I get my user script, defined in "data:" url, installed
> easily in GreaseMonkey?
> 
> Thanks,
> Julien
> 
> Here's an example of generated script (I'm using base64 encoding right
> now, but I may get ride of that):
> data:text/javascript;base64,Ly8gPT1Vc2VyU2NyaXB0PT0KLy8gQG5hbWUgICAgICAgICAgICAKLy8gQG5hbWVzcGFjZSAgICAgICAKLy8gQGRlc2NyaXB0aW9uICAgICAKLy8gQGluY2x1ZGUgICAgICAgICAKLy8gQGV4Y2x1ZGUgICAgICAgICAKLy8gPT0vVXNlclNjcmlwdD09CihmdW5jdGlvbigpIHsKICAgLy8gbWFrZSBhIGNvcHkgb2YgdGhlIGFycmF5IG9mIGxpbmtzIHNvIHdlIGRvbid0IG1vZGlmeSBpdCBhcyB3ZSBpdGVyYXRlIG92ZXIgaXQKICAgdmFyIG9yaWdfcGFnZV9saW5rcyA9IGRvY3VtZW50LmxpbmtzOwogICB2YXIgcGFnZV9saW5rcyA9IG5ldyBBcnJheShvcmlnX3BhZ2VfbGlua3MubGVuZ3RoKTsKICAgZm9yICh2YXIgaT0wOyBpIDwgcGFnZV9saW5rcy5sZW5ndGg7IGkrKyl7CiAgICAgICBwYWdlX2xpbmtzW2ldID0gb3JpZ19wYWdlX2xpbmtzW2ldOwogICB9CiAgIGZvciAodmFyIGk9MDsgaSA8IHBhZ2VfbGlua3MubGVuZ3RoOyBpKyspewogICAgICAgLy9hbGVydChwYWdlX2xpbmtzW2ldLmhyZWYpOwogICAgICAgaWYgKHBhZ2VfbGlua3NbaV0uaHJlZi5tYXRjaCgvLnRvcnJlbnQkL2kpKSB7CiAgICAgICAgICAgdmFyIHNwYW4gPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCdzcGFuJyk7CiAgICAgICAgICAgdmFyIGNvZGVfc3RyID0gIjxhIGhyZWY9XCIiOwogICAgICAgICAgIGNvZGVfc3RyICs9IHBhZ2VfbGlua3NbaV0uaHJlZjsKICAgICAgICAgICBjb2RlX3N0ciArPSAiXCI+bmV3IGxpbms8L2E+IjsKICAgICAgICAgICBzcGFuLmlubmVySFRNTCA9IGNvZGVfc3RyOwogICAgICAgICAgIC8vYWxlcnQoY29kZV9zdHIpOwogICAgICAgICAgIHBhZ2VfbGlua3NbaV0ucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUoc3BhbiwgcGFnZV9saW5rc1tpXS5uZXh0U2libGluZyk7CiAgICAgICB9CiAgIH0KfSkoKTsK
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list