CorporateGolfXtra 2024
+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Golf Guru Nat Williams is on a distinguished road Nat Williams's Avatar
    Join Date
    Oct 2005
    Location
    Barrhaven
    Posts
    2,176

    Hiding Specific Forums from "New Posts" Using Greasemonkey

    This is in response to the post on the off topic section:
    http://forum.ottawagolf.com/showthre...659#post424659

    I've written up a little greasemonkey script that will hide forums of your choice from the "New Posts" section.

    For those not familiar with Greasemonkey, it is a Firefox plugin that allows you to manipulate websites from the client side. For more information: https://addons.mozilla.org/en-US/fir.../greasemonkey/

    If you aren't using Firefox, check out this article, which can show you how to use this script in your preferred browser: http://www.pcworld.com/article/18410...nd_safari.html

    It is important to note that because "New Posts" is a custom search, this script will also filter your search results. That said, you can simply turn off the script when needed.

    You may notice that when this script filters the page, you end up with fewer posts than the normal 20 per page. This is because this is a client side script. You've been sent 20 posts by the server, but only those you wanted to see are still visible. In other words, if there are only 17 links on the page, 3 have been hidden by the script.


    -------------------------
    Once you've installed Greasemonkey (following the steps in the above link), copy the text below (below title "File Contents") into a new file and save as "OGCustomizeNewPosts.user.js" <- ensure that it ends with .user.js or it will not work (this is the file type, so .user.js.txt will be invalid). You should have everything you see written in blue below, and nothing else in the file. Once you've got the file, set whichever forums you want to hide to "false" (directions in the file contents), save the document, then drag the document onto your open Firefox window. This installs the file.

    If you decide to change your settings (i.e. switch more forums to true or false), you'll have to reinstall the script (again, simply by dragging it onto the screen). Once installed it will continue to block the specified forums from the "New Posts"/"Search" page until you disable it.

    DAN - I wasn't able to attach the file as a .js, or even as a ZIP file, which is why I posted it as text.

    FILE CONTENTS:
    Code:
    // ==UserScript==
    // @name OttawaGolf.com - hide forums from "new posts" link
    // @namespace CustomizeNewPosts
    // @description Removes specific forums from the "new posts" section of OttawaGolf.com
    // @include http://forum.ottawagolf.com/search.php*
    // @author Nathaniel Williams
    // ==/UserScript==
    
    
    //By default, every forum is shown. To remove specific results from your search,
    //replace "true" at the end of the line (below) that contains the forum's name with "false" (no quotation marks)
    var s=document.getElementsByTagName('a');
    var availableForums = new Array();
    availableForums[0] = new Forum('Discussion Forums - General',4,true);
    availableForums[1] = new Forum('Discussion Forums - Local Stuff',19,true);
    availableForums[2] = new Forum('Discussion Forums - Introductions and Greets',67,true);
    availableForums[3] = new Forum('Discussion Forums - Tour Talk',27,true);
    availableForums[4] = new Forum('Discussion Forums - Rules of Golf',3,true);
    availableForums[5] = new Forum('Discussion Forums - Instruction',6,true);
    availableForums[6] = new Forum('Discussion Forums - Travel',53,true);
    availableForums[7] = new Forum('Playing the Game - Arrange a Game',66,true);
    availableForums[8] = new Forum('Playing the Game - Trash Talk',98,true);
    availableForums[9] = new Forum('Equipment - Golf Clubs',5,true);
    availableForums[10] = new Forum('Equipment - Club Making & Components',28,true);
    availableForums[11] = new Forum('Equipment - Scotty Cameron',82,true);
    availableForums[12] = new Forum('Equipment - Other Equipment',90,true);
    availableForums[13] = new Forum('Home Simulators - General',101,true);
    availableForums[14] = new Forum('Home Simulators - Hardware',105,true);
    availableForums[15] = new Forum('Classified Ads - Local Deals',103,true);
    availableForums[16] = new Forum('Classified Ads - Right Hand Drivers',77,true);
    availableForums[17] = new Forum('Classified Ads - Right Hand Woods',80,true);
    availableForums[18] = new Forum('Classified Ads - Right Hand Irons',78,true);
    availableForums[19] = new Forum('Classified Ads - Right Hand Sets',9,true);
    availableForums[20] = new Forum('Classified Ads - Left Hand Clubs',10,true);
    availableForums[21] = new Forum('Classified Ads - Putters',79,true);
    availableForums[22] = new Forum('Classified Ads - Scotty Cameron Putters',81,true);
    availableForums[23] = new Forum('Classified Ads - Other Golf Ads',13,true);
    availableForums[24] = new Forum('Classified Ads - Components & Tools',70,true);
    availableForums[25] = new Forum('Classified Ads - Other Stuff',29,true);
    availableForums[26] = new Forum('Classified Ads - Business Networking',92,true);
    availableForums[27] = new Forum('Golf Humour - Golf Jokes',63,true);
    availableForums[28] = new Forum('Golf Humour - Naughty Golf Jokes',64,true);
    availableForums[29] = new Forum('Off Topic - Almost Anything',20,true);
    availableForums[30] = new Forum('Off Topic - Humour',40,true);
    availableForums[31] = new Forum('Off Topic - Sports',39,true);
    
    for (var i = 0; i < s.length; i++){
        var a=s[i];
        if (a.getAttribute('href') != null){
            if (!CheckIfHidden(a.getAttribute('href'))){
                a.parentNode.parentNode.parentNode.style.display='none';
            }
        }
    }
    
    function Forum(strTextName, intForumID, boolIncludeInSearch){
        this.DisplayName = strTextName;
        this.ForumID = intForumID;
        this.IsAvailable= boolIncludeInSearch;
    }
    
    function CheckIfHidden(strLink){
        for (var x=0; x < availableForums.length; x++){
            if (a.getAttribute('href').indexOf('forumdisplay.php?' + availableForums[x].ForumID + "-") != -1)
            {
                return availableForums[x].IsAvailable;
            }
        }
        //no match - prevent error - assume available
        return true;
    }
    

    Last edited by Nat Williams; 11-22-2011 at 07:37 AM.
    [SIZE=1]NCGT Ryder Cup Team [COLOR=black]Green [/COLOR](06,07,08)[/SIZE]
    [SIZE=1]OG / TGN Ryder Cup Team [COLOR=black]Ottawa [/COLOR](07) [/SIZE]

  2. #2
    Hall of Fame jvincent is on a distinguished road jvincent's Avatar
    Join Date
    Mar 2004
    Location
    Ottawa
    Posts
    7,686
    Thanks Nat. I use Chrome, so I`ll give it a whirl on that and let you know how it works.
    Not fat anymore. Need to get better at golf now!

  3. #3
    Golf Guru Nat Williams is on a distinguished road Nat Williams's Avatar
    Join Date
    Oct 2005
    Location
    Barrhaven
    Posts
    2,176
    Hey John - I just noticed it didn't copy over correctly in my original post. I've edited it, and the code up there should work, just remember to set the forums you want to hide to "false".
    [SIZE=1]NCGT Ryder Cup Team [COLOR=black]Green [/COLOR](06,07,08)[/SIZE]
    [SIZE=1]OG / TGN Ryder Cup Team [COLOR=black]Ottawa [/COLOR](07) [/SIZE]

  4. #4
    Golf Guru Nat Williams is on a distinguished road Nat Williams's Avatar
    Join Date
    Oct 2005
    Location
    Barrhaven
    Posts
    2,176
    Arrh it looks like the rich text editor for the forum is screwing up some of the code.

    a.parentNode.parentNode.parentNode.style.display=' none';

    if (a.getAttribute('href').indexOf('forumdisplay.php? ' + availableForums[x].ForumID + "-") != -1)


    there shouldn't be a space before the word none
    there shouldn't be a space after the ? in forumdisplay.php?

    Both will have to be removed when you are creating the file - the forum is adding them so I can't get rid of them in my post.

    [SIZE=1]NCGT Ryder Cup Team [COLOR=black]Green [/COLOR](06,07,08)[/SIZE]
    [SIZE=1]OG / TGN Ryder Cup Team [COLOR=black]Ottawa [/COLOR](07) [/SIZE]

  5. #5
    Team Match Play Champ 2009 hoolio is on a distinguished road hoolio's Avatar
    Join Date
    Mar 2004
    Location
    Barrhaven (HMB)
    Posts
    2,389
    Awesome, Thanks Nat. Once you follow the instructions in Post #4, it works like a charm.

    If the rich text editor is messing with your original post, would putting everything in the [ CODE ] tags bypass that?
    Let's put a Smile on that Face!

  6. #6
    Hall of Fame jvincent is on a distinguished road jvincent's Avatar
    Join Date
    Mar 2004
    Location
    Ottawa
    Posts
    7,686
    Hmmm, in order to use scripts I have to switch to Chrome beta. Need to think about that for a bit.
    Not fat anymore. Need to get better at golf now!

  7. #7
    Founder Kilroy is on a distinguished road Kilroy's Avatar
    Join Date
    Jun 2001
    Location
    Ottawa
    Posts
    22,281
    Just a note ...
    Unfortunately the script will fail when forums are added, removed or re-categorized. It happens rarely but OG can't officially promise to support this script going forward. This sort of thing is the reason we don't install plugin scripts on the forum anymore... an update to the forum happens and if the author of the script is unaware or has moved on to other things - people are left without a working feature they like to use. It is simple enough for the "savy" to edit themselves, but that isn't everyone so if you use it just keep that in mind.

    Thanks Nat I am sure many will find it useful and I certainly appreciate the contribution.
    Life dinnae come wit gimmies so yuv got nae chance o' gitt'n any from me.

  8. #8
    Golf Guru Nat Williams is on a distinguished road Nat Williams's Avatar
    Join Date
    Oct 2005
    Location
    Barrhaven
    Posts
    2,176
    Quote Originally Posted by hoolio View Post
    Awesome, Thanks Nat. Once you follow the instructions in Post #4, it works like a charm.

    If the rich text editor is messing with your original post, would putting everything in the [ CODE ] tags bypass that?
    Good call - didn't realize that tag was available here, seems to have solved the issue!
    [SIZE=1]NCGT Ryder Cup Team [COLOR=black]Green [/COLOR](06,07,08)[/SIZE]
    [SIZE=1]OG / TGN Ryder Cup Team [COLOR=black]Ottawa [/COLOR](07) [/SIZE]

  9. #9
    Golf Guru Nat Williams is on a distinguished road Nat Williams's Avatar
    Join Date
    Oct 2005
    Location
    Barrhaven
    Posts
    2,176
    Quote Originally Posted by Kilroy View Post
    Just a note ...
    Unfortunately the script will fail when forums are added, removed or re-categorized. It happens rarely but OG can't officially promise to support this script going forward. This sort of thing is the reason we don't install plugin scripts on the forum anymore... an update to the forum happens and if the author of the script is unaware or has moved on to other things - people are left without a working feature they like to use. It is simple enough for the "savy" to edit themselves, but that isn't everyone so if you use it just keep that in mind.

    Thanks Nat I am sure many will find it useful and I certainly appreciate the contribution.
    Dan brings up a good point.

    I am proceeding with best intentions and plan on updating the script as needed, but things can change. Best bet is to post to this thread if a change is needed, that way even if I'm not available someone else may be able to post the new update. As it stands now any new forums would simply not be configurable without an update to the code (they would always return no match, which by default show the content).
    [SIZE=1]NCGT Ryder Cup Team [COLOR=black]Green [/COLOR](06,07,08)[/SIZE]
    [SIZE=1]OG / TGN Ryder Cup Team [COLOR=black]Ottawa [/COLOR](07) [/SIZE]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 3
    Last Post: 08-15-2008, 11:16 PM
  2. Replies: 2
    Last Post: 04-06-2008, 11:37 AM
  3. Time of "New Posts" are incorrect
    By The Saint in forum General Golf Talk
    Replies: 3
    Last Post: 03-29-2007, 09:37 PM
  4. Getting thru the "New Posts"
    By faldo in forum General Golf Talk
    Replies: 5
    Last Post: 08-25-2004, 12:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts