On Jun 29, 7:31 am, Joachim Ott <
Joachim....@gmail.com> wrote:
> var list = // collect links here
> var listindex = 0;
>
> var http_callback = function (responsetext) {
> if (responstext) { ...}
> if (list[listindex]) // make_next_request
>
> }
>
> http_callback("");
I'm sorry, but it seems the sections of code you glossed over are
precisely the ones I'm having trouble grasping. I guess I'm not as
clear on callbacks and recursive code as I should be, so bear with me
while I go thru this.
You define the list, a counter for the list, and the callback function
for GM_xmlhttpRequest to use (presumably "onload", but probably
"onerror" as well), but then, instead of doing an XHR directly, you
call the callback function yourself, with an empty response text
(actually, the response variable for an XHR callback is a five-element
object, not just text, so maybe this should be [] or null instead),
and you let the callback kick off an XHR for the "next" (first) item
in the list.
However (and here's where it gets murky for me), the XHR call returns
immediately (before the fetch is actually finished), and the callback
proceeds to end of function, whereupon IT returns to the line after
the callback call - without knowing if there's any data to process yet
or not.
Yes, when XHR recursively calls the callback that called it (say that
five times fast!), it'll test things and decide whether to go with
what it got or make another XHR, but by that time, the main line code
has ALREADY proceeded without it.
Where's the part that gets the main line code to STOP until either the
response I need is received, or the list of URLs is exhausted?