1. Hi there, Guest

    Only registered users can really experience what DLP has to offer. Many forums are only accessible if you have an account. Why don't you register?
    Dismiss Notice

Greasemonkey Script for Work By Author

Discussion in 'General Discussion' started by PinstripedPajamas, Nov 9, 2011.

  1. PinstripedPajamas

    PinstripedPajamas Sixth Year DLP Supporter

    Joined:
    Jul 27, 2010
    Messages:
    174
    Gender:
    Male
    Location:
    Canada
    I've been having fun learning javascript the last couple weeks and decided to write something useful to get some practice in.

    To make reading in WBA easier, this greasemonkey script allows you to hide/show posts not written by the author, as well as to hide/show the left bar (with the avatars and usernames and such).

    http://userscripts.org/scripts/show/117661

    This has only been tested on Firefox 8

    I'm still learning, and I'm sure there are bugs. I can't take all credit for this either, because my brother did a good share of the javascript.
     
    Last edited: Nov 9, 2011
  2. Beonid

    Beonid Seventh Year DLP Supporter

    Joined:
    Jul 12, 2008
    Messages:
    201
    Location:
    Melbourne
    Very handy - you might want to add this, though.

    Code:
    // @include        https://forums.darklordpotter.net/showthread.php?t=*
    No bugs that I can find.
     
  3. PinstripedPajamas

    PinstripedPajamas Sixth Year DLP Supporter

    Joined:
    Jul 27, 2010
    Messages:
    174
    Gender:
    Male
    Location:
    Canada
    Good call. Fixed.

    ---------- Post automerged at 10:23 AM ---------- Previous post was at 08:49 AM ----------

    To any admins who might read this:

    There is no way to determine the OP's user ID if you are not on the thread's first page. To get around this, the script creates an iframe with the first page of the thread inside from which the script grabs the Op's ID. Essentially, whenever you change pages, it loads the site twice.

    Could the OP's ID be placed somewhere on each page? An example would be adding the OP's username after the thread's title (ex. Harry Potter and the Boy Who Lived - by The Santi), or hell, even an element hidden with display:none would work.

    The script works as is, but it would work better if it didn't need to wait for the page to load twice (and would use less bandwidth).
     
  4. Rubicon

    Rubicon High Inquisitor DLP Supporter

    Joined:
    Apr 8, 2011
    Messages:
    551
    Location:
    US
    This is really cool. I'm installing it now.

    /puts on my optimizer's hat

    You can save a ton of bandwidth by using an XMLHttpRequest instead of an iframe. The cool thing about that is it only downloads the HTML of the page you want - whereas an iframe downloads the HTML, plus all the images and scripts and other resources (which is a much bigger bandwidth hit).

    You can also "remember" the author's user id using Greasemonkey storage, so you only need to load the front page once per thread.

    There are other ways you could optimize further (like caching all the authors ahead of time when the user visits the WBA index), but at that point, the bandwidth used by an XMLHttpRequest is so small you probably don't even need to worry.
     
  5. PinstripedPajamas

    PinstripedPajamas Sixth Year DLP Supporter

    Joined:
    Jul 27, 2010
    Messages:
    174
    Gender:
    Male
    Location:
    Canada
    Ooooh, shiny. I'll have to look into XMLHttpRequest and Greasemonkey storage when I get home (or perhaps in my hour of learning freetime at work).

    It occurs to me however that when I load the iframe it won't be reloading any images (aside perhaps a couple signatures) or scripts because they will have loaded already in the parent window. Well, unless the user has caching disabled for some asinine reason.
     
  6. silverlasso

    silverlasso Minister of Magic DLP Supporter

    Joined:
    Dec 7, 2007
    Messages:
    1,302
    Location:
    San Francisco
    Super useful and cool. I haven't ever written a Greasemonkey script, so I didn't realize this was possible (although it makes a lot of sense).