// Greasemonkey http://greasemonkey.mozdev.org/
//
// ==UserScript==
// @name          Lycaeum Forum
// @description   Larger edit box and iframe, use Google for search.
// @namespace     http://deoxy.org/gm
// @include       http://forums.lycaeum.org*
// ==/UserScript==

(function() {
  function addGlobalScript(code) {
    var head, script;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.innerHTML = code;
    head.appendChild(script);
  }
  addGlobalScript(
    "function doSearch() { hmm = prompt('Search Lycaeum forums\\nWhen blank \"ok\" loads the Lycaeum search page.', '');"+
    "if (hmm == '' || hmm == ' ') { location.href = 'http://forums.lycaeum.org/cgi-bin/ultimatebb.cgi?ubb=search' }"+
    "else if (hmm) window.open('http://www.google.com/search?q=site%3Aforums.lycaeum.org+'+escape(hmm));}"
  );
  var hrefs = document.getElementsByTagName('a');
  if (hrefs) {
    for (var i = 0; i < hrefs.length; i++) {
      var uri = hrefs[i].href;
      if (uri.match(/^http:\/\/forums.lycaeum.org\/cgi-bin\/ultimatebb.cgi\?ubb=search/)) {
        hrefs[i].href = 'javascript:doSearch()';
        break;
      }
    }
  }
  var area = document.getElementsByTagName('textarea');
  if (area) {
    for (var i = 0; i < area.length; i++) {
      area[i].style.width  = '100%';
      area[i].style.height = '400px';
    }
  }
  var frame = document.getElementsByTagName('iframe');
  if (frame) {
    for (var i = 0; i < frame.length; i++) {
      frame[i].style.height = '400px';
    }
  }
  var loc = location.href;
  if (loc.match(/ubb=whos_online/)) {
    var td = document.getElementsByTagName('td');
    for (var i = 0; i < td.length; i++) {
      td[i].align = 'left';
      var txt = td[i].innerHTML;
      if (txt.match(/(A|P)M</)) {
        txt = txt.replace(/\s((A|P)M<)/,'&nbsp;$1');
        td[i].innerHTML = txt;
      }
    }
  }
})();

