FW: [Greasemonkey] Including other JS files and using "class" and
custom styles
Philip Friedman - Auto Europe
philip at autoeurope.com
Fri Aug 4 11:23:27 EDT 2006
Stefano,
The regexp in the xmlhttprequest is only to make the example work regardless
of it's URL. Notice the libraryTest.user.js Greasemonkey @include directive
(as in executes based on the URL of) references itself, so in the contrived
example document.location.href contains the path of the library.js file URL.
In the real world, you will want to replace everything after "url:" with the
URL to YOUR library.js file. It may be a literal. It may be anywhere
xmlhttpRequest can find it.
I append the URL with +'?'+Math.random() to force the latest version while I
am modifying the library. There are performance issues to consider when
requesting large files from remote servers.
--
Regards, Phil Friedman - Auto Europe
|-----Original Message-----
|From: Stefano POGLIANI [mailto:stefano at poglianis.net]
|Sent: Friday, August 04, 2006 9:54 AM
|To: philip at autoeurope.com
|Subject: Re: [Greasemonkey] Including other JS files and using
|"class" and custom styles
|
|I am not sure I fully understand this, Philip.
|
| 1. what's the meaning of the regexp in the xmlhttprequest call?
| 2. can I include from a "different site"? I mean, my GM script is
| stored someowhere on the client's PC and I want it to access a
| Javascript file that is on my web server...
| 3. not sure I understand what you mean by "@includes
|itself" and what
| does not make sense in the real world.
|
|Thanks for your patience
|regards
|/Stefano
|
|
|Philip Friedman - Auto Europe wrote:
|> Maybe not "straightforward" by Anthony's standards, but it
|does "include"
|> library.js in libraryTest.user.js as desired.
|>
|> Here's the example, that works for the two files in the same
|directory
|> on the server. Note that libraryTest.user.js @includes
|itself, so the
|> URL construction won't make sense in the real world.
|>
|> File libraryTest.user.js:
|>
|> // ==UserScript==
|> // @name LibraryTest
|> // @namespace /phil
|> // @description Library Test
|> // @include http://*libraryTest.user.js
|> // @exclude
|> // ==/UserScript==
|>
|> GM_xmlhttpRequest( { method:'GET'
|> , url:document.location.href.replace(/\/[^\/]*$/,'/library.js')
|> , onload: onLoadLibrary
|> } );
|>
|> function onLoadLibrary(rsp) {
|> eval(rsp.responseText);
|> libraryAlert();
|> }
|>
|> File library.js:
|>
|> function libraryAlert() {
|> alert('libraryAlert');
|> GM_log('libraryAlert');
|> }
|>
|> --
|> Regards, Phil Friedman - Auto Europe - 207-842-2069
|>
|>
|> |-----Original Message-----
|> |From: greasemonkey-bounces at mozdev.org
|> |[mailto:greasemonkey-bounces at mozdev.org] On Behalf Of Anthony
|> |Lieuallen
|> |Sent: Friday, August 04, 2006 9:33 AM
|> |To: greasemonkey at mozdev.org
|> |Subject: Re: [Greasemonkey] Including other JS files and using
|> |"class" and custom styles
|> |
|> |On 8/4/2006 4:18 AM, Stefano POGLIANI wrote:
|> |> 1. Does it work including an external Javascript script
|inside a GM
|> |> script?
|> |
|> |The only straightforward way is to copy and paste the source in.
|> |There's no "include" statement like in some other languages.
|> |
|> |> 2. Is there a way where I could use some "static HTML"
|to shortcut
|> |> the development time? If yes, does someone have an example?
|> |
|> |There's a number of ways. For example:
|> |http://www.arantius.com/article/dollar-e
|> |
|> |> 3. one of the issues related to my poor knowledge of JS is
|> |that, when
|> |> programmatically creating my widgets, I do not know
|how to set a
|> |> custom CSS class (the equivalent of saying <div
|class="myclass">
|> |> ..... how can I specify in Javascript this?)
|> |
|> |Since "class" is a reserved word in JavaScript, you have to use
|> |something else. In this case, className.
|> |
|> |> 4. associated to the latter. If I create my own CSS
|classes, can I
|> |> store their definition in a CSS style sheet file and
|"import" it
|> |> in the GM script? If yes, how?
|> |
|> |Yes.
|> |http://diveintogreasemonkey.org/patterns/add-css.html
|> |
|> |> 5. Final one. Can I use XUL inside a GM script?
|> |
|> |That question is a bit too open ended for me to understand fully; I
|> |can't be sure, because I don't know what you're really
|trying to do,
|> |but I suspect the answer is no.
|> |_______________________________________________
|> |Greasemonkey mailing list
|> |Greasemonkey at mozdev.org
|> |http://mozdev.org/mailman/listinfo/greasemonkey
|> |
|> _______________________________________________
|> Greasemonkey mailing list
|> Greasemonkey at mozdev.org
|> http://mozdev.org/mailman/listinfo/greasemonkey
|>
|
|
More information about the Greasemonkey
mailing list