Skip to content

Instantly share code, notes, and snippets.

@geekdinazor
Created September 17, 2015 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekdinazor/4d4b08afe76fe060a92e to your computer and use it in GitHub Desktop.
Save geekdinazor/4d4b08afe76fe060a92e to your computer and use it in GitHub Desktop.
function replacer (numpost)
{
while (numpost>=1)
{
if (!document.getElementById(numpost))
{
alert(numpost+"th post is missing! Please contact the webmaster.")
numpost-- ;
continue;
}
var post = document.getElementById(numpost).innerHTML ;
var index = post.indexOf("@") ;
var nums = "0123456789" ;
var refnum = "" ;
if (index<0)
{
numpost-- ;
continue ;
}
else
{
var x = index+1 ; //position of the character after @
while (nums.indexOf(post.charAt(x)) >= 0)
{
refnum = refnum + post.charAt(x) ;
x++ ;
}
var newpost = '<a href="#' + refnum + '">@' + refnum + '</a>' ;
if (refnum)
{
var old = "@" + refnum ;
document.getElementById(numpost).innerHTML = post.replace(old, newpost) ;
}
numpost-- ;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment