AutoHotkey Community

It is currently May 26th, 2012, 2:58 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Annoying text colorizer
PostPosted: January 12th, 2008, 11:21 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Just because I was bored, I made a script that turns words in a forum post all different colors using BBCode. Isn't that annoying? Especially since the yellow isn't really readable on a light background. And because this forum allows color tags inside code tags, I can even colorize the script itself! Isn't that annoying?
Code:
#c:: ;Win+C
;Colorize text using BBCode.
Send ^c
InputBox TempText, Enter Colors, Example: Red Blue Green,,, 120,,,,, Red Orange Yellow Green Blue Magenta
If ErrorLevel
   Return
Temp2 := Clipboard
Temp2 := RegExReplace(Temp2, "i)COLOR", "C[/COLOR][COLOR=¢0£0®]O[/COLOR][COLOR=¢0£0®]L[/COLOR][COLOR=¢0£0®]O[/COLOR][COLOR=¢0£0®]R")
Temp2 := RegExReplace(Temp2, "(\s+)", "[/COLOR]$1[COLOR=¢0£0®]")
Temp2 := "[COLOR=¢0£0®]" . Temp2 . "[/COLOR]"
Loop
{
   Loop Parse, TempText, %A_Space%
   {
      StringReplace Temp2, Temp2, ¢0£0®, %A_LoopField%
      If ErrorLevel
         Goto ColorizeDone
   }
}
ColorizeDone:
Clipboard := Temp2
Send ^v
Return

Of course I had to fudge it a little since it would have tripped up if its own special sequence of ¢0£0® was in the text.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 1:52 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Nice! It looks such an important script that I could not resist to simplify a bit ;)
Code:
colors = Black,Red,Orange,Brown,Green,Blue,Magenta
StringSplit
col, colors, `,

#c
:: ; Win-C: Colorize text using BBCode.
   Send
^c
   t
:= RegExReplace(ClipBoard,"m)\w+","$0" Chr(166)), s := ""
   Loop
Parse, t,% Chr(166)
      i
:= mod(A_Index,col0)+1, s .= "[" . "color=" . col%i% . "]" . A_LoopField . "[" . "/color]"
   ClipBoard
:= s
   Send
^v
Return


Edit: Bugfix to color the separator correctly


Last edited by Laszlo on January 13th, 2008, 2:15 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 1:56 am 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
:lol: antidote:
Code:
send ^a


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 3:07 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Nice, I knew mine was a little clunky. But now you can't enter custom color themes. How about a compromise.
Code:
#c:: ; Win-C: Colorize text using BBCode.
   Send
^c
   InputBox
colors, Enter Colors, Example: Red Blue Green,,, 120,,,,, Red Orange Yellow Green Blue Magenta
   If
ErrorLevel
      Return

   StringSplit
col, colors, %A_Space%
   t
:= RegExReplace(ClipBoard,"m)\w+","$0" Chr(166)), s := ""
   Loop
Parse, t,% Chr(166)
      i
:= mod(A_Index,col0)+1, s .= "[" . "color=" . col%i% . "]" . A_LoopField . "[" . "/color]"
   ClipBoard
:= s
   Send
^v
Return

[edit] Hmm, maybe something's wrong with this. Every once in a while it misbehaves and garbles the results.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 6:09 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Try clearing the clipboard before sending ^c and add "ClipWait 2" before the RegExReplace line. It could be that the clipboard is not yet set when the script wants to use it. A Sleep 50 before "Send ^v" could also be helpful, sometimes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 6:30 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Randomly coloured characters are more annoying...
...and gradients are much cooler. 8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 6:38 am 
lexikos wrote:
...and gradients are much cooler.

...try putting a gradient in a sig...you'll run outta 255 chars before you get off even a 5 char gradient-message...that 255 limit...a) needs to be raised...to at least 3019...b) needs to not count bbcode in the limit...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 5:13 pm 
Offline

Joined: December 23rd, 2007, 5:46 pm
Posts: 7
@lexikos
how do you make this ?
Quote:
...and gradients are much cooler. 8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 8:31 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
Probably here or somewhere similar.

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 9:07 pm 
Offline

Joined: January 19th, 2007, 9:09 pm
Posts: 147
Woot thanks for that link!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 9:25 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
w00t thanks for that link!
abcdefghijklmnopqrstuvwxyx
strange lol ...
omg red shift!

Code:
coltxt(str, a = 0x000000, i = -1) {
   f = %A_FormatInteger%
   SetFormat, Integer, Hex
   VarSetCapacity(bc, StrLen(str) * 24)
   If i = -1
      i := 0xff // StrLen(str)
   i &= k := 0xffffff
   Loop, Parse, str
   {
      c := SubStr(000000 . SubStr((a + i * (A_Index - 1)) & k, 3), -5)
      bc = %bc%[color=#%c%]%A_LoopField%
   }
   SetFormat, Integer, %f%
   Return, bc
}

MsgBox, % clipboard := coltxt("w00t thanks for that link!", 0xbe, 0x80000)
 . "`n" . coltxt("abcdefghijklmnopqrstuvwxyx")
 . "`n" . coltxt("strange lol ...", 0x333333, 0x102030)
 . "`n" . coltxt("omg red shift!", 0xff << 16, -0x100000)

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2008, 1:10 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Bravo! That's a neat effect and a neat implementation. Though I'm still kind of partial to the crazy looking text created by my original script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2008, 3:03 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Superfraggle wrote:
Probably here or somewhere similar.
Nope, I used a parsing loop. 8) It was a little simpler than Titan's script, since it only did black -> blue.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 17th, 2008, 12:48 am 
just wonderin if this actually works


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 17th, 2008, 12:55 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Guest1 wrote:
just wonderin if this actually works

Wondering if what works?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot] and 25 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group