You can convert the code nearly one-on-one:
text = text.replace(/@+([a-z0-9]+(\.?[-_a-z0-9]+)*){2,255}/g, "<a href='http://$0.".site::$domain_only."'/>$0</a>");
text = text.replace("='http://@", "='http://");
And you will need to replace site::$domain_only
with its value, e.g.:
var domain_only = '…';
text = text.replace(/@+([a-z0-9]+(\.?[-_a-z0-9]+)*){2,255}/g, "<a href='http://$0."+domain_only+"'/>$0</a>");
text = text.replace("='http://@", "='http://");
But I would rather use this regular expression:
/@+((?:[a-z0-9]+(?:\.?[-_a-z0-9]+)*){2,255})/g
Then you can use the match of the first group directly and don’t need to remove the @
afterwards:
var domain_only = '…';
text = text.replace(/@+((?:[a-z0-9]+(?:\.?[-_a-z0-9]+)*){2,255})/g, "<a href='http://$1."+domain_only+"'/>$1</a>");