// ==UserScript==
// @name           Postcounter
// @namespace      http://froschlaich.com
// @description    Zeigt die Anzahl der Posts auf der aktuellen Seite an

// @include       http://82.149.226.131/bb/thread.php*
// @include       http://forum.counter-strike.de/bb/thread.php*
// @include       http://forum.cstrike.de/bb/thread.php*
// @include       http://forum.mods.de/bb/thread.php*
// ==/UserScript==

// set counting var to 0
var count = 0;

var newThreadLinks = new Array();

// we will use anchors with the reply id to identifie a post
// first we need all links in an array
var allLinks = document.getElementsByTagName('a');

// walk through the array
for(var i=0; i<allLinks.length; i++) {
    // check if the link name contains "reply_" which identifies it as a reply anchor
    if(allLinks[i].name.match(/reply\_/)) {
        // increase the counter
        count++;
    }
    // obviously it is not a reply anchor, but maybe it's the new thread link...
    else if(allLinks[i].href.match(/newthread\.php/)) {
        // indeed, it is one of two new thread links! push it into the array, so we can easily add the counter later
        newThreadLinks.push(allLinks[i]);
    }
}

// we collected the new thread objects. now let's display the counter
for(var k=0; k<2; k++) {
    var counterSpan = document.createElement('span');
    counterSpan.innerHTML = "<br />("+count+"/30 Posts) ";

    newThreadLinks[k].parentNode.insertBefore(counterSpan, newThreadLinks[k]);
}
