Hello.  The general task that you are describing seems entirely possible
in Greasemonkey, with some possible caveats.

Pont wrote:
> Hi all,
> 
> I am a student from Japan and now I have to do some project and I
> would like to write some greasemonkey userscript and actually I am in
> doubt whether it could be able to implement or not as a userscript and
> I would like you to give me some advices and suggestions.
> 
> Firstly, I would like to describe what I want to do. Although it's not
> so complicated, it's a bit educational. I want to retrieve some XML
> databases and use it in the userscript.
> 
>     * First when a script is loaded into the browser, I will get all
> the text from the web page.
>     * And I already have my own XML databases in my Apache Web Server
> ( more than 20 XML files and in one XML file, there would be more than
> 75 records).

You can certainly request each of these files from Greasemonkey, but
doing so for all of them on every page load is going to be painfully
slow.  You may want to add an aggregated view of the XML files that is
created on the server-side that you can simply request once from
Greasemonkey.  You could also change the format to JSON, which is much
faster to get into a usable form in JavaScript than XML.

>     * I will match those keywords in my XML file with each word (text
> node) from the web page.
>     * And if any match is found, I will change those words in the web
> page to hyperlinks and show the modified page to the user.

What you are describing is very similar to what "autolink" scripts do.
You can find an example of this type of script by searching on
userscripts.org for "autolink".

>     * There would be same keyword in more than two or three XML files
> or may be in the same XML file and in that case, I will provide a pop-
> up menu in which user can choose the link. But it would be the ranked
> list of link like some search engine. So, I also would like to include
> some algorithms like retrieving and comparing the retrieved data from
> the web page and then ranking the keywords.

You can certainly do this in JavaScript.

> What I would like to implement for every web page loaded into the
> browser and I just only have to implement it in client-side.(it's my
> project limitation)
> 
> So, do you think I can implement it as a Greasemonkey userscript or
> not. I have already written a userscript for one XML file using
> xmlhttpRequest. It has no problem. But I am not sure it is ok for a
> large XML databases and the userscript I implemented has no algorithm
> for same keyword case (bullet 5).

The primary limitation of XML, alluded to above, is that it is slow to
traverse in JavaScript.  While you can use XPath to speed things up
somewhat, using a lighter-weight format like JSON will probably be
significantly faster (as well as much simpler from a Greasemonkey
programming perspective, as JSON produces native JavaScript data
structures).

>  How do you think? Do you think Greasemonkey can handle it or has some
> limitations. Or should I implement it as a firefox extension using XUL
> or my own stand-alone extension like greasemonkey using some
> programming languages such as Java. But the limitation is that I have
> to implement it as a client-side extension.
> 
>  And if it is not be able in greasemonkey, then can someone give me
> some guidelines?
> Thanks in advance.
> With regards,
> Pont

--Tom


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to