;Inspired by BillGreen and http://stackoverflow.com/questions/4867035/how-do-i-change-the-color-of-links-in-mirc/6071100#6071100
;this is actually needed to bypass mIRC's parsing behavior of strtok(str, ":")
alias urlreg return /(\x03\d{1,2}(?:,\d{1,2})?|)(.*?)(((?:(?:http[s]?:)|(?:www)\.)\S+)|(?:\S+\.(?:com|org|edu|gov|net|tv|uk|cc|xxx|mil|co|us|se|fm|me|de|kr|sv|fr|jp|tk|be|ly|info|biz|us|in|mobi)\S*))/ig
alias urlcolor return $+($chr(3), 12, $chr(31), $1-, $chr(31), $chr(3))
alias selfurlcolor return $+($chr(3), 12, $chr(31), $1-, $chr(31), $chr(3), $color(own))
;trigger for the regex event only
on ^&$*:text:$($urlreg):*:{
;if we are in a channel, turn nick into @nick if applicable
var %nick = $iif($chan, $nick($chan, $nick).pnick, $nick)
;color all the linkes using the predefined alias above
var %msgs = $regsubex($1-, $urlreg,\1\2$urlcolor(\3)\1)
;print the message, default timestamp, highlighting options, and nick coloring
echo -tcrl normal $iif($chan, $v1, $nick) $+(<, $chr(3), $cnick($nick).color, %nick, $chr(3), >) %msgs
;prevent mIRC's default echo
haltdef
}
on &*:INPUT:*:{
if ($regex($1-,$urlreg) > 0) {
var %nick = $iif($chan, $nick($chan, $nick).pnick, $nick)
var %msgs = $regsubex($1-, $urlreg,\1\2$selfurlcolor(\3)\1)
echo -atcr normal $+($chr(3), $color(own), <, %nick, >) %msgs
.msg $iif($chan, $v1, $target) $1-
haltdef
}
}