In mIRC I want all links to look like html links (blue with an underline) so they stick out in channels and messages. I'm sure I have to write a remote 开发者_如何学Goscript but I'm not sure what the code would be.
Update: This works on the first URL matched in the text. I couldn't quite get it working with multiple links.
Please note that modifying channel output has several side-effects, most notably is that multiple spaces will be condensed to one (similar to how whitespace is treated in HTML). If you are using any other scripts that modify channel output, this may interfere or even override those scripts.
I haven't dealt with mIRC's RegEx functions before, so there may be a cleaner way of doing this:
on ^*:TEXT:*:#:{
set -u %tmp.match /((ht|f)tp[s]?:\S+)/i
if ($regex(links, $1-, %tmp.match) > 0) {
set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
echo $timestamp $chan < $+ $nick $+ > %tmp.text
halt
}
}
Notes: set -u
deletes the variable after the script runs, $chr(3)
is the Control Code for Color, 12
is the Color Number for URL Blue, and $chr(31)
is the Control Code for Underline.
The mIRC 'catcher' follows the following rules:
From the help File (/help catcher):
mIRC looks for URLs beginning with "http://", "ftp://", "gopher://", "www.", and "ftp.". mIRC also checks to make sure addresses are not added to a list if they already exist. Addresses longer than 256 characters are ignored.
As stated in the other answer, modifying the default behavior will cause a spacing compression effect, but it shouldn't be too much of an issue with this script as it will only trigger when a URL is displayed. (Additionally I used the & prefix which will make mIRC disable the event in case another script has performed an earlier default text altering and executed a /haltdef)
;this is actually needed to bypass mIRC's parsing behavior of strtok(str, ":")
alias urlreg return /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig
;the coloring alias, blue (12), underline (31)
alias urlcolor return $+($chr(3), 12, $chr(31), $1-, $chr(31), $chr(3))
;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, $urlcolor(\t))
;print the message, default timestamp, highlighting options, and nick coloring
echo -tcrl normal $iif($chan, $v1, $nick) $+(<, %nick, >) %msgs
;prevent mIRC's default echo
haltdef
}
will turn:
<@FooBar> a b c www.example.com a b c www.example.com a b c www.example.com
into:
<@FooBar> a b c ^12www.example.com a b c ^12www.example.com a b c ^12www.example.com
Edit:
My use of $target was invalid in my original answer which resulted in the issue commander_keen described. This should now be fixed.
I just wanted to add that it requires to use //echo in order to get the text output to the correct channel for me, otherwise the text will be sent to the status-window or so.
Additionally I would add the -bf and -m parameters to treat the message as normal user-message and apply the default flashing/beep settings, otherweise the message won't make the channel act as if there is a new message.
So that would sum up as //echo -bfmtrl
for jnpcl's script, even respecting the timestamp-settiings (that's the -t
)
Wiz's solution might profit from a few of those changes, too.
kind regards
PS: jnpcl's script lags the URL-highlighting for www-links without http:// and highlight in query windows, yet. Last issue can of course easily be resolved by adding a second on ^*:TEXT:*:?:{
block with //echo -bfmtl $nick < $+ $nick $+ > %tmp.text
, but I wonder if it can be done in one ON:TEXT
Handler.
Wiz's script unfortunately always ends up in sending to the status window when a link in a query is detected and the text in the query stays as is. Seems like $target
doesn't work as expected for queries, it uses the own nick, but I don't know a solution for that.
So using Wiz's regex in jnpcl's code with the improvements mentioned above ends up in the following working code in channels AND queries for http AND www links etc. for now:
;URL highlighting for channels
on ^*:TEXT:*:#:{
set -u %tmp.match /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig
if ($regex(links, $1-, %tmp.match) > 0) {
set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
//echo -bfmtlr $chan < $+ $nick $+ > %tmp.text
halt
}
}
;URL highlighting for queries
on ^*:TEXT:*:?:{
set -u %tmp.match /((?:(?:(?:http|ftp|gopher)\72\/\/)|(?:www|ftp)\.)\S+)/Sig
if ($regex(links, $1-, %tmp.match) > 0) {
set -u %tmp.text $regsubex(links, $1-, %tmp.match, $chr(31) $+ $chr(3) $+ 12 $+ \t $+ $chr(3) $+ $chr(31))
//echo -bfmtlr $nick < $+ $nick $+ > %tmp.text
halt
}
}
I'd be happy to see Wiz's solution work with queries, too. That would be cleaner than two event-blocks in my eyes. Until then the above code should represent a best of both.
精彩评论