Since my lack of programming experience prevents me from contributing anything more substantive to the community, I thought I'd share my script that makes using BBCode on the forums easier. I don't like the tag buttons and since I'm using Firefox they further cause scrolling issues in the post boxes; this script has solved that problem for me.
If no text is highlighted it will simply enter the open and close tags for whatever attribute is requested but if text is highlighted it will wrap the highlighted text in tags. I have tried to use the forum hotkeys wherever possible.
An additional feature of the "
url" tag is that if you have copied a URL to the clipboard prior to executing the hotkey it will wrap the URL in the open tag.
The "
quote", "
size" and "
color" tags will all display an input box where you can enter the value to be wrapped in the open tag; if no value is entered the tags themselves will be sent.
The "
list" hotkey will also display an input box but if no value is entered it will send the list tags without the "=". If no text is highlighted the list tags will be sent with one list item tag enclosed, but if text is highlighted a list item tag will be applied after every linefeed encountered.
Any comments or suggestions are welcome:
Code:
;
; AutoHotkey Version: 1.0.48
; Language: English
; Platform: Win9x/NT
; Author: sinkfaze <privateuniverse@whoever.com>
;
; This script provides an alternate method to utilize the forum tags.
; The script utilizes the forum's hotkeys for certain tags wherever possible
; and [url] and [quote] are assigned to two different hotkeys to accomodate
; instances with and without and "=" parameter. If text within the forum post
; is hightlighted the tags will wrap the highlighted text automatically;
; otherwise the opening and closing tags will just be sent.
; Here are the available tags and their hotkeys:
;
; Alt+b sends Bold tags
; Alt+i sends Italic tags
; Alt+u sends Underline tags
; Alt+c sends Code tags
; Alt+p sends Image tags
; Alt+w sends URL tags
; Alt+q sends Quote tags
; Alt+f sends the Font tags
; Alt+g sends the Color tags
; Alt+o sends the List tags
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
PVerify() {
global PTitle
WinGetActiveTitle, PTitle
}
BBCodeSimple(Left, Right) {
Current := Clipboard
Clipboard =
Send ^c
ClipWait, 0
r := StrLen(Right)
Clipboard := Left . Clipboard . Right
Send ^v
Send % "{LEFT " r "}"
r = 0
Current := Clipboard
return
}
BBCodeInner(Left, Right) {
Current := Clipboard
Clipboard =
Send ^c
ClipWait, 0
If InStr(Left,"url")
{
if InStr(Current,"http://")
{
StringReplace, Current, Current, (, `%28
StringReplace, Current, Current, ), `%29
StringReplace, Left, Left, url, url=%Current%
Clipboard := Left . Clipboard . Right
Send % "{Raw}" Clipboard ""
Send {LEFT 6}
Clipboard := Current
return
}
else
{
Clipboard := Left . Clipboard . Right
Send ^v
Send {LEFT 6}
Clipboard := Current
return
}
}
else if InStr(Left,"quote")
{
InputBox, Name, Username, Enter the username to quote., , 195, 120
if ErrorLevel
{
Clipboard := Left . Clipboard . Right
Send ^v
Send {LEFT 8}
Clipboard := Current
Return
}
else
{
StringReplace, Left, Left, quote, quote="%Name%"
Clipboard := Left . Clipboard . Right
Send ^v
Send {LEFT 8}
Clipboard := Current
Return
}
}
else if InStr(Left,"size")
{
InputBox, Size, Font Size
, Enter any font size from 1`-29.`nMost common`: 7`, 9`, 12`, 18`, 24, , 205, 135
if ErrorLevel
{
Clipboard := Left . Clipboard . Right
Send ^v
Send {LEFT 7}
Clipboard := Current
Return
}
else
{
StringReplace, Left, Left, size, size=%Size%
Clipboard := Left . Clipboard . Right
Send ^v
Send {LEFT 7}
Clipboard := Current
Return
}
}
else if InStr(Left,"color")
{
InputBox, Color, Font Color
, Enter a color by name(red) or hexadecimal(`#FF0000)`nMost common names`: red`, green`, blue`, brown, , 325, 135
if ErrorLevel
{
Clipboard := Left . Clipboard . Right
Send ^v
Send {LEFT 8}
Clipboard := Current
Return
}
else
{
StringReplace, Left, Left, color, color=%Color%
Clipboard := Left . Clipboard . Right
Send ^v
Send {LEFT 8}
Clipboard := Current
Return
}
}
}
BBCodeList() {
Current := Clipboard
Clipboard =
Send ^c
ClipWait, 0
InputBox, LType, List Tags
, Enter the list type(if any).`n'1' for numerical`, 'a' for alphabetical, , 225, 135
if (LType)
{
Clipboard := "[list=" LType "][*]" . Clipboard
StringReplace, Clipboard, Clipboard, `n, `n[*], All
Clipboard .= "[/list]"
Send ^v
Send {LEFT 7}
Clipboard := Current
Return
}
Else
{
Clipboard := "[list][*]" . Clipboard
StringReplace, Clipboard, Clipboard, `n, `n[*], All
Clipboard .= "[/list]"
Send ^v
Send {LEFT 7}
Clipboard := Current
Return
}
}
$!b::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeSimple("[b]", "[/b]")
Else
Send !b
return
$!i::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeSimple("[i]", "[/i]")
Else
Send !i
Return
$!u::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeSimple("[u]", "[/u]")
Else
Send !u
Return
$!c::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeSimple("[code]", "[/code]")
Else
Send !c
Return
$!p::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeSimple("[img]", "[/img]")
Else
Send !p
Return
$!w::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeInner("[url]", "[/url]")
Else
Send !w
Return
$!q::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeInner("[quote]", "[/quote]")
Else
Send !q
Return
$!f::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeInner("[size]", "[/size]")
Else
Send !f
Return
$!g::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeInner("[color]", "")
Else
Send !g
Return
$!o::
PVerify()
if (InStr(PTitle,"Post a reply") || InStr(PTitle,"Post a new topic") || InStr(PTitle,"Edit post"))
BBCodeList()
Else
Send !o
Return
EDIT: It is also worth mentioning that I added some StringReplace commands in the "
url=" tags to acommodate parenthesis within copied URLs, with respect to
Laszlo's reported bug.
20090401: Changed the 'Send ^v' command in the first loop for url= to 'Send % "{Raw}" Clipboard ""' to accomodate URLs with the '#' sign