// ==UserScript==
// @name my.opera.com - Forum pagelinks
// @author Øystein R. Ryen
// @description  Makes navigating on the my.opera.com forums easier by
//			adding links to each page of the forum threads.
//			This script is deprecated since the forum setup
//			has changed.
// @ujs:category site: enhancements
// @ujs:published 2005-05-29 20:38
// @ujs:modified 2005-10-26 23:13
// @ujs:documentation http://userjs.org/scripts/site/enhancements/myopera-forum-pagelinks 
// @ujs:download http://userjs.org/scripts/download/site/enhancements/myopera-forum-pagelinks.js
// ==/UserScript==


/* 
 * This script is granted to the Public Domain
 */

if (window.location.href.match(/^http:\/\/my\.opera\.com\/forums.*forumid/)) {
  document.addEventListener('load', function(ev) {

    /*********************/
    var perpage=25;              //Posts per Thread, modify to match your settings
    var maxlinks=20;             //maximum number of links to show
    /********************/

    var elements=document.getElementsByTagName('tr'),i=0,element,rep;
    while(element=elements.item(i++)) {
      if (element.hasAttribute('class') && element.getAttribute('class')=='bit' && (rep = element.childNodes[4].childNodes[0].innerText) >= perpage) {
        var linknr = Math.floor(rep / perpage);
        var target = element.childNodes[2].childNodes[3].href;
        for (var x=0; x<maxlinks&&x<linknr;x++) {
          element.childNodes[2].appendChild(document.createTextNode(' '));
          element.childNodes[2].appendChild(document.createElement('a'));
          element.childNodes[2].lastChild.innerText = x+2;
          element.childNodes[2].lastChild.href = target + '&perpage=' + perpage + '&pagenumber=' + (x+2);
        }
      }
    }
  }, false);
}
