// ==UserScript==
// @namespace     http://shog9.com/greasemonkey/scripts/
// @name          CPExpandAll
// @author        Joshua Heyer
// @description   Add an "Expand All" option to Code Project forums
// @version       1.0
// @include       http://*.codeproject.com/*
// @include       http://*.codetools.com/*
// @include       http://*.thecodeproject.com/*
// ==/UserScript==

var refreshLink = document.evaluate("//a[text()='Refresh']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if ( refreshLink )
{
   var expandBtn = document.createElement("BUTTON");
   expandBtn.className = "FormButton";
   expandBtn.textContent = "Expand All";
   expandBtn.addEventListener("click", function(event)
   {
      var forumTable = document.getElementById("ForumTable");
      if ( !forumTable )
         return;
      var messages = document.evaluate("./tbody/tr[4]/td/table/tbody/tr", forumTable, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
      if ( messages )
      {
         for (i=0; i<messages.snapshotLength; ++i)
         {
            messages.snapshotItem(i).style.display = "";
         }
      }
   }, false);
   refreshLink.parentNode.insertBefore(expandBtn, refreshLink.nextSibling.nextSibling);
}
//.user.js