AutoHotkey Community

It is currently May 27th, 2012, 1:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Easy BBCode
PostPosted: April 1st, 2009, 7:23 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Last edited by sinkfaze on April 2nd, 2009, 5:35 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 5:39 pm 
thanks,

that's a pretty cool script.

I'd also recommendthis firefox Add-on for
posting bbcodes, HTML & Wikicodes (yes it got 3 in 1)

Image


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2009, 5:41 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
A new version of the code has been posted. I changed the "font" tags to "size" tags(oops) and I've eliminated the dual hotkeys for the "url" and "quote" tags. I also eliminated including the '=' sign by default in the "url" "quote" "size" and "color" tags when no text has been highlighted; the tags themselves will just be sent (a change which allowed me to condense the dual hotkeys for "url" and "quote" into one).

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2009, 12:28 pm 
I thought to myself that it's not that bad to adopt a well known interface/Gui. So I started to create the BoBoCoder as a AHK-Forum-Editor-look-alike ... (TBH, still in alpha-trial-mode)

Image


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2009, 1:14 pm 
Offline

Joined: July 17th, 2008, 9:46 am
Posts: 225
there already exists a bb code editor :)
http://de.autohotkey.com/forum/topic30.html
Image
Thanks AGU :)
and °digit° made an extended version of AGUs BBCodeWriter, which can be found here: http://de.autohotkey.com/forum/viewtopic.php?t=4434
Image
Greets,
DHMH


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2009, 3:51 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
Yeah, I've used the BBCode Editor before and I thnk it's nice but 1) I can't download it on my corporate network and 2) I didn't really want to use an external app despite the benefits of having an external backup copy of my text. This is just a quick and easy way around the hassles of using the forum with Firefox.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2009, 5:02 am 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
i made mine just a couple days before you, but mine gets no love :( (that was to be expected, as all my stuff sinks :? )
http://www.autohotkey.com/forum/viewtop ... highlight=
i think the forum now has plenty of BBCode editors to choose from now^^

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2009, 6:00 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
That's a fascinating adaption of maj's CmnDlg function to pull up the color picker! Pain in the butt that even if you cancel out of the box it still puts a color in there anyway.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2009, 7:38 am 
Quote:
but mine gets no love
Well, I've started the BoBoCoder as my-own-private-challenge (just to feel ashamed now that I didn't finished it :oops::lol:).
AGU's BBC, IMHO is overwhelming, but I didn't like its frontend*. So it's with other BBCs, but I'm (and propably others are) interested in the (core functionality) of those apps.

And hey, what about to make it skinnable??

JM2€Cs 8)

* which is based on Windows classic theme, but looks quite Delphi-stylish. Not my favourite. It's "only" a visual thing, right - like to decide to drive a Hummer or a Ferrari.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, Yahoo [Bot] and 14 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