views:

58

answers:

2

Hi guys.

Here is my problem: I've registered some callbacks into a Yahoo event driven webpage (betfair.com market views) and am trapping the betsPlaced events with a handler.

So far so simple.

Next stage is to get the event back into greasemonkey land, and while I know that from greasemoney space you can call unsafeWindow.stuff, there is no reverse operation (by design).

So if I want to send the contents of the event over, say, a cometd queue, my carefully set up jquery, greasemonkey, YUI2, betfair environment fails by telling me that unsafeWindow processes cant call GM_ajax stuff. This is obviously safe and sane, but it basically stops me doing what I want to do.

Has anyone tried doing this (ignore the cometd stuff, just general ajax calls) and succeeded?

I've had a look at pages like this: http://wiki.greasespot.net/0.7.20080121.0%2B_compatibility but it doesnt appear to work for all the calls.

A: 

Using a setTimout as that page you linked to in the Greasespot wiki explains, should work, I'm guessing you implemented the work around incorrectly.

Erik Vold
There are scope problems. When the timer thread is triggered to execute it does not have vilisiblity of the function I define in the setTimeout and fails. I was trying to call a function in the global namespace of the greasemonkey script from the setTimeout.
Chilly
+1  A: 

This doesn't seem clear to me. Why can't the events be trapped from the GM end using addEventListener(), preventDefault(), stopPropagation(), etc?

Anyway, worst case, can't you do something like this?

  1. Create a hidden iframe, div, or whatever, and have GM monitor it for DOM change events.
  2. Write the captured event information into that node.
  3. Greasemonkey then parses the data and uses GM_ajax as you see fit.
Brock Adams