Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

AJAX replacement for voting buttons

by bsdz (Friar)
on Jan 02, 2007 at 12:55 UTC ( [id://592549]=monkdiscuss: print w/replies, xml ) Need Help??

Esteemed monks

For those who find voting can be a little arduous here at the monastery whilst waiting for a page to refresh. I have created a simple GreaseMonkey script for Firefox that replaces bog-standard voting buttons with a lightweight AJAX alternative. It can be found here.

Somewhat inspired by the thread "AJAX-based Perlmonks.com?".

I have also placed this link on bsdz's scratchpad.

Updated: I have considered adding the JavaScript inline but decided not to since I do not want to maintain several copies. (And it's not written in Perl!). Another problem is that GreaseMonkey needs the file to have a "user.js" extension for it to auto-install. If you have any other suggestions on improvements then please /msg me or reply to this post.

Replies are listed 'Best First'.
Re: AJAX replacement for voting buttons
by McDarren (Abbot) on Jan 03, 2007 at 02:04 UTC
    After installing this, I've found that I can no no longer see anything within <code>tags. All I see are the code "blocks" with no content. Here is a screenshot in case you're not sure what I mean.

    Using Firefox 2.0 on WinXP.

    Cheers,
    Darren

      TT elements are being stripped in an attempt to remove the existing ++ and -- text, but TT elements are also used for code tags.

      It's just a question of fixing the XPath query. "//tt" needs to be replaced. I think "//div[@class='vote']//tt" will do the trick.

        Yes, I had started noting that peculiar behaviour. I have updated the script with your new XPath query. Thanks.
Re: AJAX replacement for voting buttons
by b10m (Vicar) on Jan 03, 2007 at 09:15 UTC

    Couple of things:

    • I use http://perlmonks.org/, not http://www.perlmonks.* ;-)
    • The ++ and -- links are not really user friendly. I'd opt for the radio buttons with a button next to them
    • Your script breaks the voting booth
    • Why do I have to refresh the page to see the ratings? Isn't the point to _not_ to refresh?
    --
    b10m

    All code is usually tested, but rarely trusted.
      • You can add http://perlmonks.org/* to your "Included pages" when you "Manage User Scripts..." in GreaseMonkey.
      • Subjective. I feel they are more user friendly as they are single-click.
      • I'll take a look at the voting booth. It must use a similar form to post-voting. Update: Looks like this is a JavaScript bug when calling document.evaluate on an XPath - appears to be picking nodes with similar XPaths! Best workaround is to disable the VB node.
      • You do save refreshes especially in the long run. You no longer need to refresh the page (by pressing the "vote" button) before moving to another node.
      I must admit I was not expecting to please everyone ;-)
        • This was more a pointer, you may want to include that in your next release
        • Ok, so we disagree
        • Nice workaround ;-)

        The last point requires some more text, so I'll comment on that here.

        IMHO, your GM script (no matter funny and handy) will not help much. You still request a lot of pages and AFAIK, the content is still being returned to the client (we just ignore it at this point). Since we already receive the whole page back, why not strip out the relevant information to update the new "reputation"?

        Also, why not update the "votes left" in the XP Nodelet at the same time? (I don't believe you do that now). That way, in the end, we end up with slightly more page requests, but at least it's fun ;-)

        Right now, I'm actually putting more stress on the PM server, for usually I vote for a few nodes, then hit the Vote button and all is handled in a single page request. I see the amount of votes I have left, and I see the node's reputation. Now I launch a request for every single vote, and I have to launch another one, to see the result!

        "I must admit I was not expecting to please everyone ;-)"

        You've posted code to a critical (and often cynical) audience. Expect feedback ;-)

        --
        b10m

        All code is usually tested, but rarely trusted.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: monkdiscuss [id://592549]
Approved by marto
Front-paged by andyford
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-03-19 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found