AutoHotkey Community

It is currently May 27th, 2012, 10:45 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: AHK forum link helper
PostPosted: February 24th, 2008, 11:33 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Many of my comments in the forum include links to other sites and topics. I like to title my links because URLs tend to be long and undescriptive. This requires manually editing the [URL] tags for every link; however, so I wrote a short script.

All it does is wait for a link to be copied to the clipboard (anything starting with "http://"). It then waits 5 seconds for you to activate a forum posting window. If you do, it formats the link on the clipboard to look like: [url=link]title[/url]. The script has 2 settings for the title of the link. It can be either the title of the Window that the URL came from or the text from the middle of the URL, in between the "www" and ".com" (the URL isn't required to have www or .com in it, those are just examples).

Code:
#SingleInstance force
#Persistent
#NoEnv
SetBatchLines, -1
SetTitleMatchMode, slow
;
TypeOfTitle= 1   ;1|2   1=Title of the URL's Window.
;         2=URL text between "www" and ".com"
;
Menu, Tray, Icon, clipbrd.exe
Menu, Tray, Tip, AHK forum link helper
return

OnClipboardChange:
If (SubStr(clipboard,1,7) != "http://")
 return
WinGetActiveTitle, title
WinWaitActive,,http://www.autohotkey.com/forum/posting.php?mode=, 5
If !(ErrorLevel)
{
 If TypeOfTitle = 1
 {
  If title contains - Windows Internet Explorer
   StringTrimRight, title, title, 28
 }
 Else If TypeOfTitle = 2
 {
  StringSplit, URL, clipboard, .
  StringReplace, URL1, URL1, http://
  title := InStr(clipboard,"www.")=8 ? URL2:URL1
 }
 If pos := InStr(clipboard,"&highlight=")
  clipboard := SubStr(clipboard,1,(pos-1))
 clipboard = [URL=%clipboard%]%title%[/URL]
}
return


Last edited by jaco0646 on May 11th, 2008, 8:07 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 4:08 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
I had been meaning to do something similar: grab the title automatically from the destination of the link. After seeing your post, I had to write it:
Code:
$^+v::
    uri := Clipboard
   
    Tooltip, Retrieving %uri%...
   
    COM_Init()
    WebRequest := COM_CreateObject("WinHttp.WinHttpRequest.5.1")
    COM_Invoke(WebRequest, "Open", "GET", uri)
    COM_Invoke(WebRequest, "Send")
    ResponseText := COM_Invoke(WebRequest, "ResponseText")
    COM_Release(WebRequest)
    COM_Term()
   
    RegExMatch(ResponseText, "(?<=<title>).*?(?=</title>)", Title)
   
    ToolTip

    if Title !=
        Clipboard = [url=%uri%]%Title%[/url]
    Send ^v
return
Requires COM Standard Library. (Note: I used the script to generate the bbcode for that link.) 8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 6:16 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
@lexiKos
Nice! You reproduced my code in a manner I don't even understand. :lol: Why am I not surprised? :P

Since my script was already monitoring the clipboard, I incorporated it into some more code to keep a Clipboard History. I know there's already some great clipboard helper scripts out there on the forum, so this one is more of a lightweight alternative, with the forum link helper included of course.

>DOWNLOAD<


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 9:20 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
jaco0646 wrote:
Nice! You reproduced my code in a manner I don't even understand.
:lol:
Everything from COM_Init() to COM_Term() is basically equivalent to UrlDownloadToVar; i.e. it downloads the target of the link into ResponseText. The regular expression then finds the value of the <title> element.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 22 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