// ==UserScript==
// @name          Wikipedia Redirect
// @namespace     http://simon.incutio.com/code/greasemonkey/
// @description	  Follows redirects on Wikipedia
// @include       http://*.wikipedia.org/*
// ==/UserScript==

/*

HTML to scan for:

<div id="contentSub">(Redirected from <a href="/w/index.php?title=Gameplay&amp;redirect=no" title="Gameplay">Gameplay</a>)</div>

URL to go to:

<li id="ca-nstab-main"
  class="selected"><a href="/wiki/Game_play">Article</a></li>

*/

var div = document.getElementById('contentSub');
if (div) {
  var r = /Redirected from <a href=.*?title=([^&]+)/;
  var match = r.exec(div.innerHTML);
  if (match) {
    window.location = document.getElementById('ca-nstab-main').getElementsByTagName('a')[0].href;
  }
}
