Friday, February 4, 2011

Forum Image Tags


// ==UserScript==
// @name Forum Image Tags
// @version 1.0.5
// @namespace Kjoe51689 & Toccata6767
// @description Will replace all [img][/img] tags with a real image in the forum. Allowing the use of Images on forums without clicking a link
// @include http://goallineblitz.com/game/forum_thread.pl?*
// ==/UserScript==

window.setTimeout(function() {
 ImageReplacement();
}, 1000);

function ImageReplacement() {

 //Create array of elements
 var element= getElementsByClass("post_content_inner");

 //Search array and replace the image tags with the html tags
 for (i = 0; i < element.length; i++) {
  var postHTML = element[i].innerHTML;
  while(postHTML.indexOf("[/img]") != -1)
  {
   var beginIndex = postHTML.indexOf("[img]<a href");
   var endIndex = postHTML.indexOf("[/img]</a>");
   var strUrl = postHTML.substring(beginIndex, endIndex+10);
   var strUrlRedux = strUrl.replace("<a href=\"", "");
   endIndex = strUrl.indexOf("[/img]");
   strUrlRedux = strUrlRedux.substring(0, endIndex-3);
   postHTML = postHTML.replace(strUrl, strUrlRedux);
   postHTML = postHTML.replace("[img]", "<img src = \"");
   postHTML = postHTML.replace("[/img]", "\">");
  }
  while(postHTML.indexOf("[+1]") != -1)
  {
   
   postHTML= postHTML.replace("[+1]", "<img src = \"http://img18.imageshack.us/img18/9347/plus1g.gif\">");
   postHTML[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[nsfw]") != -1)
  {
   postHTML= postHTML.replace("[nsfw]", "<img src = \"http://img193.imageshack.us/img193/3281/nsfw.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[bump]") != -1)
  {
   postHTML= postHTML.replace("[bump]", "<img src = \"http://img840.imageshack.us/img840/1701/bumpc.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[-1]") != -1)
  {
   postHTML= postHTML.replace("[-1]", "<img src = \"http://img96.imageshack.us/img96/9161/minus1.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[combine]") != -1)
  {
   postHTML= postHTML.replace("[combine]", "<img src = \"http://img543.imageshack.us/img543/9862/combine.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[addict]") != -1)
  {
   postHTML= postHTML.replace("[addict]", "<img src = \"http://img690.imageshack.us/img690/968/addicts.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[heman]") != -1)
  {
   postHTML= postHTML.replace("[heman]", "<img src = \"http://img840.imageshack.us/img840/1339/hemanf.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[pwned]") != -1)
  {
   postHTML= postHTML.replace("[pwned]", "<img src = \"http://img189.imageshack.us/img189/1755/pwnedm.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[gtfo]") != -1)
  {
   postHTML= postHTML.replace("[gtfo]", "<img src = \"http://img809.imageshack.us/img809/5082/gtfo.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[help]") != -1)
  {
   postHTML= postHTML.replace("[help]", "<img src = \"http://img88.imageshack.us/img88/5947/helpw.gif\">");
   element[i].innerHTML = postHTML;
  }
  while(postHTML.indexOf("[worthless]") != -1)
  {
   postHTML= postHTML.replace("[worthless]", "<img src = \"http://img143.imageshack.us/img143/4650/worthless.gif\">");
   element[i].innerHTML = postHTML;
  }



               element[i].innerHTML = postHTML;
 }
}

//Function created by www.anyexample.com
function getElementsByClass( searchClass, domNode, tagName) { 
 if (domNode == null) domNode = document;
 if (tagName == null) tagName = '*';
 var el = new Array();
 var tags = domNode.getElementsByTagName(tagName);
 var tcl = " "+searchClass+" ";
 for(i=0,j=0; i<tags.length; i++) { 
  var test = " " + tags[i].className + " ";
  if (test.indexOf(tcl) != -1) 
   el[j++] = tags[i];
 } 
 return el;
} 

0 comments:

Post a Comment