mIRC Homepage
Posted By: Fenton Single click URLs to open - 29/01/11 05:08 AM
It would be really nice if there were an option to open URLs with one click rather than two. Perhaps even coloring them similar to how they are on websites.
Posted By: jaytea Re: Single click URLs to open - 29/01/11 08:30 AM
in the mean time, both of these things can be scripted in a way that recreates mIRC's default behaviour to an extent that should be satisfactory for the majority of users.

you can detect single clicks on (whole) words using a HOTLINK event. validating a URL is trickier, and i've attempted to create a pattern that fits mIRC's own detection scheme as close as possible while staying relatively simple:

Code:
; Detects single clicks on URLs.
; Holding shift or ctrl will have them open in a new window, if your browser permits.
;
on ^*:hotlink:*:*:{
  if ($mouse.key & 1) && ($regex($1, $urlre)) {
    url -a $+ $iif($mouse.key & 6, n) $regml(1)
  }
  halt
}

; $urlre
; Returns a regular expression that matches URLs in a string and captures them in \1.
;
alias urlre {
  return /(*UTF8) (?:^|[\x20\x09]) [\Q '<([{" \E]* \K (                              $&
    (?: (?:irc|gopher|https?|ftps?|telnet):// 	| (?:www|ftp)\. )                    $& 
    [^\x20\x09]+\.[^\x20\x09]+? ) (?= [\Q ')]}>"., \E]* (?:[\x20\x09]|$) ) /giSx
}


various subtleties have been neglected either because they're difficult to account for (determining the character position of the mouse on the word in on HOTLINK) or because adding support would really inflate the code (such as replicating precisely mIRC's handling of brackets/quotes touching a URL - this cannot be done in a single regular expression).

as for the colouring, here's an example that uses the $urlre pattern included in the snippet above:

Code:
on &^*:text:*:*:{
  echo -mbflirt $iif(#, #, $nick) $+(<, $left($nick(#, $nick, a, r).pnick, 1), $nick, >) $urlcolour($1-)
  haltdef
}

; $urlcolour(text)
; Returns 'text' with URLs appropriately coloured and underlined.
;
alias urlcolour {
  return $regsubex($1, $urlre, $+($chr(31), $chr(3), 12\1, $chr(3), $chr(31)))
}

; American-friendly version!
;
alias urlcolor return $urlcolour($1)


with this, the loss of certain parts of mIRC's own behaviour might be more apparent, a topic about which one could certainly write a lot!
Posted By: Fenton Re: Single click URLs to open - 29/01/11 11:54 AM
Thanks, those work nicely, but is there a way to still have the address book color nicknames? Seems the url color script makes all nicknames black regardless of the address book settings.
Posted By: pball Re: Single click URLs to open - 29/01/11 04:17 PM
It's a bit long but this colors the nick the same as mirc does.

Code:
$+(<,,$nick($chan,$nick).color,$iif($left($nick($chan,$nick).pnick,1) isin $prefix,$v1),$nick,>)


Just replace the "$+(<, $left($nick(#, $nick, a, r).pnick, 1), $nick, >)" part with that and you should be good
Posted By: Tomao Re: Single click URLs to open - 29/01/11 06:38 PM
Originally Posted By: pball
It's a bit long but this colors the nick the same as mirc does.
You're actually making it longer by using $chan lol But it doesn't make any difference really.
Posted By: pball Re: Single click URLs to open - 29/01/11 11:03 PM
Using $chan over # is just a personal preference for me. I started using $chan so it seems normal and # I don't like since I always forget it's a special character.
Posted By: Fenton Re: Single click URLs to open - 30/01/11 08:08 AM
Sorry to be a bother but when I replaced it all nicks are still black, they also have a 1 in front of them.
Posted By: argv0 Re: Single click URLs to open - 30/01/11 09:13 AM
I'd suggest replacing the control codes with $chr(3) to be more easily copied.
Posted By: Tomao Re: Single click URLs to open - 30/01/11 10:05 AM
I don't quite get the deal with isin $prefix when the whole thing can just be:
Code:
$+(<,$chr(3),$nick(#,$nick).color,$nick(#,$nick).pnick,$chr(3),>)
Posted By: jaytea Re: Single click URLs to open - 30/01/11 12:24 PM
Originally Posted By: Tomao
I don't quite get the deal with isin $prefix when the whole thing can just be:
Code:
$+(<,$chr(3),$nick(#,$nick).color,$nick(#,$nick).pnick,$chr(3),>)


it serves a purpose. $nick().pnick returns the nick with the full set of associated prefixes. that means if Bob is both oped and voiced on #chan, $nick(#chan, Bob).pnick = @+Bob

the point of my $left() and pball's $iif() is to extract only the highest prefix (if one exists) and prepend it to $nick to yield the prefix+nick combination that mIRC shows by default.
Posted By: drum Re: Single click URLs to open - 30/01/11 02:36 PM
The script given in this thread was meant more as an example to demonstrate the way you might go about changing the way URLs appear via scripting, not really a feature complete implementation to be directly copied. (Even with the control codes fixed, it wouldn't handle query colors or your own text.)
Posted By: Tomao Re: Single click URLs to open - 30/01/11 07:35 PM
Thanks, jaytea. That explains it.
© mIRC Discussion Forums