mIRC Home    About    Download    Register    News    Help

Print Thread
Single click URLs to open #229295 29/01/11 05:08 AM
Joined: Jan 2011
Posts: 5
F
Fenton Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jan 2011
Posts: 5
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.

Re: Single click URLs to open [Re: Fenton] #229298 29/01/11 08:30 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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!


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Single click URLs to open [Re: jaytea] #229303 29/01/11 11:54 AM
Joined: Jan 2011
Posts: 5
F
Fenton Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jan 2011
Posts: 5
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.

Re: Single click URLs to open [Re: Fenton] #229313 29/01/11 04:17 PM
Joined: Nov 2009
Posts: 295
P
pball Offline
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
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

Last edited by pball; 29/01/11 04:18 PM.

http://scripting.pball.win
My personal site with some scripts I've released.
Re: Single click URLs to open [Re: pball] #229323 29/01/11 06:38 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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.

Re: Single click URLs to open [Re: Tomao] #229329 29/01/11 11:03 PM
Joined: Nov 2009
Posts: 295
P
pball Offline
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
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.


http://scripting.pball.win
My personal site with some scripts I've released.
Re: Single click URLs to open [Re: pball] #229335 30/01/11 08:08 AM
Joined: Jan 2011
Posts: 5
F
Fenton Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jan 2011
Posts: 5
Sorry to be a bother but when I replaced it all nicks are still black, they also have a 1 in front of them.

Re: Single click URLs to open [Re: Fenton] #229339 30/01/11 09:13 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
I'd suggest replacing the control codes with $chr(3) to be more easily copied.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Single click URLs to open [Re: Tomao] #229341 30/01/11 10:05 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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),>)

Re: Single click URLs to open [Re: Tomao] #229343 30/01/11 12:24 PM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Single click URLs to open [Re: Fenton] #229344 30/01/11 02:36 PM
Joined: Dec 2002
Posts: 339
D
drum Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Dec 2002
Posts: 339
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.)

Re: Single click URLs to open [Re: jaytea] #229348 30/01/11 07:35 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Thanks, jaytea. That explains it.