[Greasemonkey] Long literal strings of html

Aaron Boodman zboogs at gmail.com
Wed Apr 13 10:50:29 EDT 2005


This is one of the things I was talking about in my latest entry on
greaseblog (http://greaseblog.blogspot.com/). I know it's quite a
departure from what we have now, but I think it's worth thinking about
since most of the manipulation people are doing is adding to the DOM.

In the short term, Mark Pilgrim introduced a trick in his first script
that I had never ever heard of before:

var s = '<foo> \
<bar> \
<monkey> \
<baz>';

which isn't complete escaping (you still have to handle ' , but it
gets remarkably close for javascript.


On 4/13/05, Steve Krulewitz <shooz at mm.st> wrote:
> Julien Couvreur wrote:
> > Question: is there any similar trick in javascript that would allow
> > putting long strings without having to care about escaping them?
> 
> One trick I used to use with Microsoft's implementation of JavaScript is
> using a function as a container for a block of text.  The block of text
> would be hidden in a comment, and when accessing the function name as a
> variable the source of the function (including comment) will be
> returned.  Something like:
> 
> function data() {
> /*
> Long block
> of text goes
> here
> */
> }
> 
> Then by doing the proper data.substring() the text in the comment could
> be extracted.  However, this does not seem to work in mozilla -- the
> source is returned sans comments.
> 
> Maybe GM could pre-process the user scripts and find delimited blocks of
> text that could be made accessible via some GM_* methods.  However, this
> might be overkill for user scripts...
> 
> cheers,
> -steve
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list