woebbi / EH_Add_H@H_DlLink

// ==UserScript==
// @name        EH_Add_H@H_DlLink
// @namespace   
// @include     http://g.e-hentai.org/?f_*
// @include     http://g.e-hentai.org/?p*
// @grant       none
// ==/UserScript==
/*
thanks to: 
http://greasemonkey.win-start.de/patterns/match-attribute.html
http://stackoverflow.com/questions/12731801/how-can-i-rewrite-links-with-javascript-or-jquery-and-a-regular-expression
http://help.dottoro.com/ljagksjc.php
http://www.w3schools.com/jsref/jsref_string.asp
http://help.dottoro.com/ljruhkuj.php
for code pieces and thought food
*/

var allLinks, thisLink, teile, newLink, teileStr, stuff;
allLinks = document.evaluate('//a[contains(@href, "hentai.org/g/")]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
/*alert("1");
alert(String(allLinks));
alert(allLinks.snapshotLength);*/
for (var i = 0; i < allLinks.snapshotLength; i++) {
  thisLink = allLinks.snapshotItem(i);
  //alert("2");
  //alert(String(thisLink.href));
  teileStr = String(thisLink);
  teile = teileStr.split("/");
  newLink = teile[0] + "//"
          + teile[1] + ""
          + teile[2] + "/"
          + "hathdler.php?gid=" 
          + teile[4] + "&t="
          + teile[5]
          ;
  stuff = document.createElement('a');
  stuff.href = newLink;
  stuff.innerHTML = '<img src="http://i.imgur.com/2SfeCLR.png">';
  //document.getElementByClass("it5").innerHTML = String(newLink);
  thisLink.parentNode.insertBefore(stuff,thisLink);
}