A greasemonky script for squadlist.co.uk

One of my hobbies is rowing, a sport that requires lots of organisation- you need one rower per seat in the boat plus one cox (most of the time) and often a bank party and/or coach to all turn up at the same time. At my club this problem is tackled using a website where each member enters their availability; this data is then used by outing cordinators to schedule sessions when the correct people can make it. On the whole this works well, but the website does some things that make it more awkward than it needs to be when I come to filling in my availabilty:

  1. Closed outings are still displayed; they clutter up the list without providing any useful information (simply being available doesn’t mean that I’m actually rowing)
  2. There are a series of options that are redundant for our club (for some reason the creator of the software thinks that coaches want specific excuses for unavailability)
  3. There are constant suggestions of going rowing at silly o’clock in the morning. This is more of a problem with the outing co-ordinators, but still something that can be fixed by software
    1. What squadlist used to look like

      Greasemonkey is an addon for Firefox that allows JavaScript to be run whenever a page is loaded; this is a perfect quick & easy way to selectively hide or remove elements from a page. My script rummages through the DOM (document object model) of the page making changes where necessary.

      If a row contains the word “closed” then it is hidden otherwise the script parses the time of the outing, which it then compares to what I have defined to be a civilised time (8am) in order to establish whether or not the proposed outing is at silly o’clock in the morning and therefore needs to be hidden. The final piece of code searches through all the options of evey drop-down box on the page and compares their values to a list of unused options, if it finds a match it marks them for deletion.

      Now when I visit squadlist I see:
      What I now see instead
      I can immediately enter and alter my availability for the upcoming week without having to navigate my way around all the rubbush that used to clutter my screen.

      squadlist.user.js:

      // ==UserScript==
      // @name        squadlist
      // @namespace   mike-worth.com
      // @include     http://cambridge99.squadlist.co.uk/rowers_availability.php
      // @version     1
      // @grant       none
      // ==/UserScript==
      
      civilisedTime=8;
      unusedOptions=[1,2,3,6,7,8];
      displayClosedOutings=false;
      
      outingsTable=document.getElementById('tblRowersAvailability');
      row=outingsTable.firstChild.firstChild;//This contains the tile 'Mens squad outings'
      
      row=row.nextSibling;//while this one has the proper column headers in it
      
      while (row.nodeType!=1){row=row.nextSibling;}//this skips any non-element nodes (like text nodes from the new whitespace etc.)
      
      //this removes whole rows if the outing is too early or already closed
      while(row=row.nextSibling){
        if (row.firstChild!=null){//this skips any non-element nodes (like text nodes from the new whitespace etc.)
          
          
          firstCellContents=row.firstChild.innerHTML//if this a a proper row we get the outing time/date otherwise we get <hr>
          if(firstCellContents!='<hr>'){
      
            time = firstCellContents.trim().split(' ')[2];
            sillyOClock=(parseInt(time.split(':')[0])<civilisedTime);
            outingClosed=(row.innerHTML.indexOf("closed")!=-1);
            
            if(sillyOClock || (outingClosed && ! displayClosedOutings)){
              row.style.display='none';
              row.nextSibling.style.display='none';//this strips out the horizontal rules in interleaved rows
            }
          }
        }
      }
      
      
      //This bit removes the unused options from the selection lists
      
      optionsToDelete=new Array();//we can't delete them as soon as we find them because it will mess up our array
      
      allOptions=document.getElementsByTagName('option');
      for(i=0;i<allOptions.length;i++){
        value=parseInt(allOptions[i].value);
        if(unusedOptions.indexOf(value)!=-1){
          optionsToDelete.push(allOptions[i]);
        }
      
      }
      for(i=0;i<optionsToDelete.length;i++){
        optionsToDelete[i].parentElement.removeChild(optionsToDelete[i]);
      }
      

Leave a Reply