[Greasemonkey] Arrgghh!!! it runs asynch!!!

Tom Emerson osnut at pacbell.net
Wed Jun 28 05:18:37 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Anton Berezin wrote:
> On Wed, Jun 28, 2006 at 01:06:35AM -0700, Tom Emerson wrote:
> 
>> by the the first "GM_xmlhttprequest" completes, the script is over and
>> done with the entire page -- only the last image gets updated!
> 
> The closures bite!  The closures bite!  Tom is confused.  :-)

no, just annoyed at the concept of a free-floating function embedded as
a parameter to another function... (where did I leave the tylenol?)

>> Now that I'm down to that last niggling detail, here is the
>> script-thus-far:
> 
> You just need a separate instance of thisCell variable by the time onload
> function fires up.  So basically, replace

I'm not entirely certain what you propose would work either -- I finally
came to the realization that I needed to pass "my own parameter" to the
callback, something along the lines of

   onload: function(responseDetails,thisCell){...}

so the particular instance (event/wakeup/whatever) of the called-back
function would "know" which anchor to update.

On that note... I'm happy to announce that as of 3:00am local time, I
finally managed to monkey up my first page :) (woo-hoo!)

What I finally realized is that there IS a bit of information that I can
(logically) "pass" to the anonymous function -- the pass itself is
indirect, but it seems to work.  Basically, the multi-digit ID that I
use to retrieve the "details" page is ALSO on the details page, and by
extension contained within the "refText" extracted out of the response.
 This gives me a common "ID" between the icon/anchor to replace, and the
replacement URL (and, in fact, solves another problem: the aspect ratio
of the photos -- the "icon" is fixed at 15x15, which is obviously too
small for most photos; at the same time, the information contained in
the member details page includes a height/width specification, so as a
result I can do this:

  var Height  =
refText.match(/http:\/\/photos.eharmony.com\/.+height="([0-9]+)"/)[1];
  var Width   =
refText.match(/http:\/\/photos.eharmony.com\/.+width="([0-9]+)"/)[1];
  var id2     = refText.match(/<input type="hidden" name="set"
value="([0-9]+)">/)[1];
      id2     = 'id' + id2;

(this brings up another headache that makes no sense -- the program gets
"the entire raw response" in a string as follows:

    onload: function(responseDetails) {
        var refText = responseDetails.responseText;

and refText.match(/some-expression/) works.

If I then try to do this:

        var newIMG = refText.match(/some extraction/g);
        var imgWidth = newIMG.match(/some sub-extraction/g);

I get the error that "newIMG.match" is not a function.  Several trials
later I hit upon the solution above, but the inconsistency drove me nuts
for quite some time)

In any case, what I did to solve this was create a GLOBAL
associative-array to store the "anchors" as they are extracted by the
document.evaluate function, using the 9-digit "member-id" as the key to
the array.  Then within the anonymous function, I create id2 using the
same methodology, this then re-creates the "key" needed to find the
"proper" anchor to replace.

Now that I've scratched my own itch -- who else would like a copy of the
final script?

- --
Top o' the Blog: It's good to be the King...
http://osnut.homelinux.net/mtblog/ya_index.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEomWNV/YHUqq2SwsRAusVAJ0d8DduDGS1QTes1W85jNOVq2F0GQCfSyrz
yfEAxTZynb1lQn5Vt7S3jhI=
=SLj8
-----END PGP SIGNATURE-----


More information about the Greasemonkey mailing list