[Greasemonkey] Intermediate web page

csaba2000 (sent by Nabble.com) lists at nabble.com
Wed Feb 8 03:53:04 EST 2006


Hi, I'd like to write a greasemonkey script and thought I'd ask if my
methodology is correct / recommended / optimal.  The basic idea is that I'd
like to use the data from a given web page to make calculations via
javascript in a foreign web page and to utilize the results in the original
web page: 

To be concrete, I want to be able to get a hint when I'm playing sudoku, but
the hint page is (on) a different domain.  When the original sudoku page is
loaded, my greasmonkey script will insert a button ("Hint") onto the page. 
When button is pressed, the current state of the page (sudoku table) will be
encoded and saved using GM_setValue
(http://diveintogreasemonkey.org/advanced/gm_getvalue.html).

Then the sudoku hint page should be brought up using GM_xmlhttpRequest
(http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html).  
GM_xmlhttpRequest has an onload callback, which I will use to read the
current sudoku state (using GM_getValue), fill out the sudoku table on hint
page, and then get the hint, which requires (simulating the) pressing (of) a
button (method=POST) on the hint page to get a new hint result page.

Now this hint result page should also be subject to greasemonkey scripts
(right?), and when I detect this page, I can extract the hint result, and
save it with GM_setValue.  Meanwhile, the original sudoku page should notice
that the result has been set and that will be its signal that it can
continue, and do something with the result.

Assuming this methodology is reasonable, I have some questions:
1.  How do I clean up after a GM_xmlhttpRequest?  After all,
GM_xmlhttpRequest brings up a new DOM, and then I will be (simulating)
pressing a button within that page to get yet another page.  If I am asking
for hints repeatedly, I could be generating quite a large number of such
requests.

2.  I assume GM_xmlhttpRequest is anychronous.  In other words, the next
line of code executes immediately.  Therefore, I should immediately follow
it with some kind of timing loop (window.setInterval) to check for the hint
result page being finished.

3.  I assume GM_xmlhttpRequest (and subsequent pages) are subject to
greasemonkey scripts as are "regular" pages.  This is probably the most
critical point in this methodology.  If not true, I would have to issue a
GM_xmlhttpRequest within the first one, which doesn't strike me as very
clean.

4.  In general a page obtained with GM_xmlhttpRequest may have its own
onload set in the HTML or added as an event listener.  Where does
GM_xmlhttpRequest's onload come in relation to these (what is the order of
execution)?

Thanks,
Csaba Gabor from Vienna
--
View this message in context: http://www.nabble.com/Intermediate-web-page-t1082020.html#a2819000
Sent from the MozDev - greasemonkey forum at Nabble.com.



More information about the Greasemonkey mailing list