AutoHotkey Community

It is currently May 27th, 2012, 3:46 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: URL Shortening
PostPosted: March 15th, 2009, 4:24 am 
Offline

Joined: March 15th, 2009, 4:16 am
Posts: 1
Using a slightly modified version of UrlDownloadToVar, I've made a wee script with a simple GUI which lets you shorten URLs.

Handy for using with Twitter or other sites.

It lets you choose between is.gd, tr.im, and TinyURL but it can be modified to work with any of the other ones easily enough.


Code:
;Win + U shortens URLs
#u::
Gui, Add, Edit, x12 y30 w280 h20 Default vLongURL, http://
Gui, Add, Text, x12 y10 w280 h20 , Enter long URL:
Gui, Add, DropDownList, x12 y60 w100 h70 vService AltSubmit, is.gd||tr.im|TinyURL
Gui, Add, Button, x142 y60 w50 h30 gOK Default, OK
Gui, Add, Button, x212 y60 w80 h30 gGuiClose, Cancel

Gui, Show, x327 y226 h105 w307, Shorten URL
SendInput {Right}
Return

OK:
Gui, Submit
If (Service==1) {
   URL = http://is.gd/api.php?longurl=%LongURL%
   shortURL := UrlDownloadToVar(URL,0)
}
Else If (Service==3) {
   URL = http://tinyurl.com/api-create.php?url=%LongURL%
   shortURL := UrlDownloadToVar(URL,0)
}
Else If (Service==2) {
   URL = http://api.tr.im/api/trim_simple?url=%LongURL%
   shortURL := UrlDownloadToVar(URL,1)
}
SendInput %shortURL%
Gui, Destroy
Return

GuiClose:
Gui, Destroy
Return



UrlDownloadToVar(URL, DeleteAmount="", Proxy="", ProxyBypass="") {
AutoTrim, Off
hModule := DllCall("LoadLibrary", "str", "wininet.dll")

;msgbox %URL%

If (Proxy != "")
AccessType=3
Else
AccessType=1
;INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
;INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
;INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
;INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS

io_hInternet := DllCall("wininet\InternetOpenA"
, "str", "" ;lpszAgent
, "uint", AccessType
, "str", Proxy
, "str", ProxyBypass
, "uint", 0) ;dwFlags

iou := DllCall("wininet\InternetOpenUrlA"
, "uint", io_hInternet
, "str", url
, "str", "" ;lpszHeaders
, "uint", 0 ;dwHeadersLength
, "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
, "uint", 0) ;dwContext

If (ErrorLevel != 0 or iou = 0) {
DllCall("FreeLibrary", "uint", hModule)
return 0
}

VarSetCapacity(buffer, 512, 0)
VarSetCapacity(NumberOfBytesRead, 4, 0)
Loop
{
  irf := DllCall("wininet\InternetReadFile", "uint", iou, "uint", &buffer, "uint", 512, "uint", &NumberOfBytesRead)
  NOBR = 0
  Loop 4  ; Build the integer by adding up its bytes. - ExtractInteger
    NOBR += *(&NumberOfBytesRead + A_Index-1) << 8*(A_Index-1)
  IfEqual, NOBR, 0, break
  ;BytesReadTotal += NOBR
  DllCall("lstrcpy", "str", buffer, "uint", &buffer)
  res = %res%%buffer%
}
; The bit I added:
StringTrimRight, res, res, DeleteAmount ;Removes new lines if necessary

DllCall("wininet\InternetCloseHandle",  "uint", iou)
DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
DllCall("FreeLibrary", "uint", hModule)
AutoTrim, on
return, res
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: TinyUrl
PostPosted: July 31st, 2010, 12:19 pm 
Offline

Joined: October 27th, 2006, 11:35 am
Posts: 5
Location: BELGIUM
Hello,

No one has answered your post yet BUT this script works very well.
I've just adapted a few lines for my comfort.

Au revoir.

_________________
lucgod1 (LIEGE - BELGIUM)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2010, 9:17 pm 
I use javascript in browser, search at userscripts.org

http://url-elongator.appspot.com
http://xpnd.it
http://sqze.it
http://long-shore.com


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

All times are UTC [ DST ]


Who is online

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