// ==UserScript==
// @name          Report Post
// @namespace     http://loucypher.wordpress.com/
// @include       http://www.extensionsmirror.nl/*showtopic=*
// @include       http://www.extensionsmirror.nl/*act=st*
// @description	  Add report button
// ==/UserScript==

function addReportButton(b, t, p) {
  var img = document.createElement('img');
  img.src = 'style_images/1/p_report.gif';
  img.setAttribute('alt', 'Report post');
  img.setAttribute('border', '0');

  var link = document.createElement('a');
  link.href = '/index.php?act=report&t=' + t + '&p=' + p;
  link.appendChild(img);

  b.parentNode.insertBefore(link, b);
}

var topic, entries, entry, topButtons, topButton;

if(location.href.match(/showtopic/))
  topic = location.href.match(/\Wshowtopic\=\d+/).toString().match(/\d+/);
else
  topic = location.href.match(/\Wt\=\d+/).toString().match(/\d+/);

entries = document.evaluate('//a[starts-with(@name, "entry")]',
          document, null, 6, null);

topButtons = document.evaluate('//a[@href="javascript:scroll(0,0);"]',
          document, null, 6, null);

for(var i = 0; i < entries.snapshotLength; i++) {
  entry = entries.snapshotItem(i).name.match(/\d+/);
  topButton = topButtons.snapshotItem(i);
  addReportButton(topButton, topic, entry);
}

