Thanks for the help.  Your explanation helped a lot, Brian.  I did
eliminate the parens,
which eliminated the browser being hung, but it's still not doing what
I want.

I've put the whole script below.  It acts on the page
https://blogs.secondlife.com/main-threads.jspa
(if you go there, you should collapse the upper box, which is called
"Channels" or "Communities",
depending on your language setting).

The page is a list of thread titles on a not-very-functional web
forum.
What my script does it to fetch the first post in each thread and
stick it into a hover tip
for each thread link.

That much works fine, but only on the first page of links.

What happens is that if someone goes to the next page, or any other
page,
they click on one of  the links in this block:

                    <!-- BEGIN pagination-->
                    <span class="jive-pagination">
                        <span class="jive-pagination-numbers">
                                <a href="#"
onclick="jiveviewthreads.setStart(0); return false;"
                                    class="jive-pagination-current"
>1</a>
                                <a href="#"
onclick="jiveviewthreads.setStart(30); return false;"
                                     >2</a>

                        </span>
                        <span class="jive-pagination-prevnext">
                                <span class="jive-pagination-prev-
none">Previous</span>
                                <a href="#"
onclick="jiveviewthreads.setStart(30); return false;" class="jive-
pagination-next">Next</a>
                        </span>
                    </span>
                    <!-- END pagination -->

and then the page is rewritten.  What I need is a way to run my script
again at this point so that all the hovertips will be inserted.

You can see below that I tried to add the click listener to the spans
that enclose the pagination links.

I put a "console.log" call in that loop so I can see in Firebug
whether it's finding the spans.  It does, and I see those
messages when I call the second and third page, but then they stop.

And still, I only get the hover tips on the very first page.

I don't see any errors in the Error Console.

Am I all mixed up?  or on the right  track?

// ==UserScript==
// @name           Second Life Forums: Show first post in hover tip
// @namespace      https://blogs.secondlife.com/
// @description    When user pauses over a thread title, a little box
shows text of first post
// @include        https://blogs.secondlife.com/*
// ==/UserScript==


// --- this function adds a text preview to the thread links ---
//
function btjSetHovertip(link, element) {

  var link_title, tempString;

  GM_xmlhttpRequest({
    method: 'GET',
    url: link,
    onload: function(page) {

      // --- this field has the text of the first post in the thread
      link_title = page.responseText.match(/_jive_plain_quote_text (.+)
\;/);
      tempString = link_title[0];

      // --- make that text more readable
      tempString = tempString.replace(/\"\;$/,'');
      tempString = tempString.replace(/\\n.gt\;/g,' ');
      tempString = tempString.replace(/^.*wrote:}{quote} +/, '');
      tempString = tempString.replace(/\\/g,'');
      tempString = tempString.replace(/{[^}]*}/g,'');
      tempString = tempString.replace(/\&amp\;/g,'&');
      tempString = tempString.replace(/\&nbsp\;/g,' ');
      tempString = tempString.replace(/\&quot\;/g,'"');

      // --- stick that text in the link's title attribute
      element.title = tempString;
    }
  });
}

// --- this updates the page: first adding hover tips, then updating
pagination links
//
function btjUpdatePage4HoverText() {

    // --- get all the links to threads
    //
    var allElements, thisElement, tmpStr;
    allElements = document.evaluate(
        "//t...@class='jive-table-cell-subject']/a",
        document,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);

    for (var i = 0; i < allElements.snapshotLength; i++) {
        thisElement = allElements.snapshotItem(i);

        // --- change the link to a more usable one and call btjSetHovertip
        //
        tmpStr = thisElement.href.replace('?tstart=0','');
        tmpStr = tmpStr.replace('/thread/','/post!reply.jspa?
thread=');
        btjSetHovertip(tmpStr, thisElement);
    }

    // --- now we need to fix the pagination links that rewrite the
page
    //
    allElements = document.evaluate(
        "//sp...@class='jive-pagination-numbers'] | //sp...@class='jive-
pagination-prevnext']",
        document,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);
    for (var i = 0; i < allElements.snapshotLength; i++) {
        thisElement = allElements.snapshotItem(i);

        // --- debug message for me to see in Firebug
        console.log("found");

        // --- add an event listener to the span that holds the pagination
links
        //
        thisElement.addEventListener("click", btjUpdatePage4HoverText, true);
    }

    return true;
}

// --- this calls the function in the first place
//
btjUpdatePage4HoverText();

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to