mermaidchel / Rachel's Haven gallery new caps fix

// ==UserScript==

// @name Rachel's Haven gallery new caps fix

// @namespace http://www.rachelshaven.com

// @description fixes the gallery links for new caps in gallery

// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @match http://rachelshaven.com/gallery/thumbnails.php?album=lastup*
// @match http://rachelshaven.com/gallery/thumbnails.php?album=toprated*
// @match http://rachelshaven.com/gallery/thumbnails.php?album=lastcom*
// @match http://rachelshaven.com/gallery/thumbnails.php?album=topn*
// ==/UserScript==
var galleryTable = document.getElementsByClassName("maintable")[0];
var links = galleryTable.getElementsByTagName("a");
var baseURL = "http://rachelshaven.com/gallery/displayimage.php?"
var valueToCut = "album=lastup&;";
var len=links.length;
var dispTest =/displayimage.php/;
for(var i=0; i<len; i++) {
    if(dispTest.test(links[i].href))
    {
    var image = links[i].href;
    var newEnd = image.substr(baseURL.length + valueToCut.length -2, image.length-1);
   var newURL = baseURL + newEnd;
   links[i].href = newURL;
    }
}