AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

URL Shortening

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Petr



Joined: 15 Mar 2009
Posts: 1

PostPosted: Sun Mar 15, 2009 3:24 am    Post subject: URL Shortening Reply with quote

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
}
Back to top
View user's profile Send private message
lucgod1



Joined: 27 Oct 2006
Posts: 5
Location: BELGIUM

PostPosted: Sat Jul 31, 2010 11:19 am    Post subject: TinyUrl Reply with quote

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)
Back to top
View user's profile Send private message
widow
Guest





PostPosted: Sat Jul 31, 2010 8:17 pm    Post subject: Reply with quote

I use javascript in browser, search at userscripts.org

http://url-elongator.appspot.com
http://xpnd.it
http://sqze.it
http://long-shore.com
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group