Foreground color replacer
Platform: mIRC
Published Jan 17, 2006
Updated Jan 18, 2006
This snippet replaces foreground colors. If you have - for instance - a black background, text with foreground colors black, darkblue and darkbrown are not or hardly readable. You can setup the foreground colors to be replaced in the table at the beginning of the snippet. The given table is suitable for black backgrounds.
In the echo command at the end of the snippet, the nickname is completed with a . for owner, @ for oper and + for voice. The server I'm usually on doesn't support halfops; you have to add that yourself if necessary.
Improvements in v1.1:
- listens to actions and notices
- addition of on/off switch in menus
- simpler setup of color replacement table
Improvements you can make for yourself:
- changing echo parameters -tlbfmr
- sending notices to all channels you are on
- changing mode char . @ + for nicks
- setup of variables in an on START event
; Snippet by noMen v1.1 - 2006
; Version 1.0 only listened for on *:TEXT, this version 1.1 also listens to on *:ACTION and on *:NOTICE
; Addition of on/off switch in menus
; Simpler color replacement table, nice suggestion KuTsuM
menu query,status,channel,menubar {
.-
.Color Replacer (= $+ $group(#colrep) $+ ): {
if ($group(#colrep) == off) { .enable #colrep }
else { .disable #colrep }
echo -a 4 Color Replacer $group(#colrep)
}
}
#colrep on
on ^*:TEXT:**:*:{
if (!$chan) && (!$window($nick)) {
query $nick
}
echo -tlbfmr $iif($chan, $chan $+(<, $iif($nick isowner $chan, ., $iif($nick isop $chan, @, $iif($nick isvoice $chan, +))), $nick, >), $nick $+(<, $nick, >)) $replace($ColRep($1-), $chr(160), )
haltdef
}
on ^*:ACTION:**:*:{
if (!$chan) && (!$window($nick)) {
query $nick
}
echo -tlbfmr $iif($chan, $chan $+(*, $chr(32), $iif($nick isowner $chan, ., $iif($nick isop $chan, @, $iif($nick isvoice $chan, +))), $nick), $nick $+(*, $chr(32), $nick)) $replace($ColRep($1-), $chr(160), )
haltdef
}
on ^*:NOTICE:**:*:{
echo -tlbfmr $active $iif($chan, $+(-, $iif($nick isowner $chan, ., $iif($nick isop $chan, @, $iif($nick isvoice $chan, +))), $nick, :, $chan, -), $+(-, $nick, -)) $replace($ColRep($1-), $chr(160), )
haltdef
}
#colrep end
alias ColRep {
; setup foreground color replacement table
; the values given below are usefull for black backgrounds, for instance:
; - black foreground (01) will be replaced with white (00)
; - dark blue foreground (02) will be replaced with dark cyan (10)
; - dark brown foreground (05) will be replaced with yellow (08)
; replace back: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
var %colrep.k = 00 00 10 03 04 08 13 07 08 09 10 11 11 13 14 15
var %colrep.s = $1-
var %colrep.r = \03(\d)(?!\d)
while ($regex(%colrep.s, %colrep.r)) {
; as long as there are single digit color codes in the input text, insert a zero
var %colrep.q = $regsub(%colrep.s, %colrep.r, 0 $+ [ $regml(1) ], %colrep.s)
}
; now find and replace valid foreground colors according to the following scheme (like mIRC does):
; FORE BACK REPLACE
; valid none yes
; valid valid no
; valid invalid yes
; invalid n,v,i no
var %colrep.r = \03(\d{2})(?!,(0|1[0-5]|[1-9]\D))
while ($regex(%colrep.s, %colrep.r)) {
; lookup found foreground color codes in the replacement table and replace them with another one
; if no valid foreground color is found, the color code will remain unchanged
; also replace with $chr(160) to prevent the regex to loop eternally
var %colrep.q = $regsub(%colrep.s, %colrep.r, $chr(160) $+ $iif($regml(1) < 16, $gettok(%colrep.k, $calc($regml(1) + 1), 32), $regml(1)), %colrep.s)
}
return %colrep.s
}