topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday April 16, 2024, 8:54 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: UrlCopy (currently a mod of Skrommel's UrlHistory)...  (Read 3506 times)

Onesimus Prime

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 15
    • View Profile
    • Donate to Member
IDEA: UrlCopy (currently a mod of Skrommel's UrlHistory)...
« on: February 18, 2010, 01:26 AM »
What I was kind of hoping for/envisioning was a portable, cross-browser (or at least IE-compatible) version of the CopyAllUrls extension for FireFox.  That extension, which is fairly flexible, can save the URLs and titles of open webpages across multiple tabs and even going back through a tab's history!  The user also defines the format for the output.

I downloaded the source for Skrommel's UrlHistory and tweaked it a bit as a first step toward this.  Right now, it uses the hard-coded shortcut keys Ctrl+Shift+C to copy the current IE tab's URL and title, Ctrl+Shift+V to paste all of these that have been copied (and empty the 'database' or whatever), Ctrl+Shift+E to empty the 'database' without pasting, and Ctrl+Shift+Q to quit.

Let me say that I don't really know AHK, so any and all alterations may be somewhat hack-ish, there's probably some now-unnecessary code, etc.  And yes, I found the thread with a similar request, but 1) I'm posting code  :), and 2) more importantly, I think my goals for this program and my implementation are slightly different...
;UrlCopy.ahk
;version 1.0.3
; changes: no longer puts URLs in tray menu
; grabs webpage address and name from current IE tab
;Skrommel @ 2006
;modified by Onesimus Prime


#SingleInstance,Force
#Persistent

applicationname=UrlCopy

changed=0
Gosub,READINI
Gosub,TRAYMENU
Return

^+c::Send, {ALTDOWN}d{ALTUP}{CTRLDOWN}c{CTRLUP}
^+e::
  ; FileRecycle, %applicationname%.htm
  FileDelete, %applicationname%.htm
  FileAppend,,%applicationname%.htm
  Gosub,TRAYMENU
  Return
^+v::
  clipboard =   ;Empty the clipboard
  FileRead,clipboard,%applicationname%.htm
  Send,{CTRLDOWN}v{CTRLUP}
  clipboard =   ;Empty the clipboard
  FileDelete, %applicationname%.htm
  Return
^+q::
  FileDelete, %applicationname%.htm
  ExitApp
  Return

; IfWinActive,ahk_class IEFrame
OnClipboardChange:
If watch<>1
  Return
If A_EventInfo<>1
  Return
If changed=1
  Return
urls=
end=
Loop
{
  start=999999
  StringGetPos,pos1,clipboard,http,,%end%
  StringGetPos,pos2,clipboard,www,,%end%
  StringGetPos,pos3,clipboard,ftp,,%end%

  If (pos1>-1)
    start:=pos1
  If (pos2<start And pos2>-1)
    start:=pos2
  If (pos3<start And pos3>-1)
    start:=pos3
  If start=999999
    Break

  StringGetPos,pos4,clipboard,%A_Space%,,%start%
  StringGetPos,pos5,clipboard,%A_Tab%,,%start%
  StringGetPos,pos6,clipboard,`n,,%start%

  end:=start
  If (pos4>-1)
    end:=pos4
  If (pos5<end And pos5>-1)
    end:=pos5
  If (pos6<end And pos6>-1)
    end:=pos6
  If (end=start)
    StringLen,end,clipboard

  length:=end-start
  StringMid,url,clipboard,%start%,%length%
  If url<>
  {
    WinGetActiveTitle,title
    ; InputBox,title,%applicationname%,Please enter comment for`n%url%,,400,150,,,,,%title%
    ; If ErrorLevel=0
      StringReplace,TitleMinusIE,title, - Windows Internet Explorer
      AutoTrim Off
      urls=%A_Space%%A_Space%%A_Space%%urls%%url%  - %TitleMinusIE%`n
  }
}
If urls<>
{
  FileAppend,%urls%,%applicationname%.htm
}
GOSUB,TRAYMENU
Return



TRAYMENU:
Menu,Tray,DeleteAll
Menu,Tray,NoStandard
Menu,Tray,Add,%applicationname%,ADD
Menu,Tray,Default,%applicationname%
Menu,Tray,Add,
Menu,Tray,Add,&Add Url...,ADD
Menu,Tray,Add,&Edit Urls...,EDIT
Menu,Tray,Add,
Menu,Tray,Add,&Settings...,SETTINGS
Menu,Tray,Add,A&bout...,ABOUT
Menu,Tray,Add,E&xit,EXIT
Menu,Tray,Tip,%applicationname%
Return


EDIT:
RunWait,Notepad.exe %applicationname%.htm,,UseErrorLevel
Gosub,TRAYMENU
Return


ADD:
InputBox,url,%applicationname%,Please enter web address,,400,150,,,,,http://
If ErrorLevel<>0
  Return
InputBox,comment,%applicationname%,Please enter comment for`n%url%,,400,150
If ErrorLevel<>0
  Return
FileAppend,%url% - %comment%`n,%applicationname%.htm
Gosub,TRAYMENU
Return


OPEN:
StringSplit,url_,A_ThisMenuItem,%A_Space%-

If run=1
{
  IfNotInString,url_1,http
  IfNotInString,url_1,ftp
  url=http://%url_1%
  Run,%url_1%,,UseErrorLevel
}
If paste=1
{
  changed=1
  clipboard=%url_1%
}
Sleep,2000
changed=0
Return


SETTINGS:
Gosub,READINI
RunWait,Notepad.exe %applicationname%.ini
Gosub,READINI
Return


READINI:
IfNotExist,%applicationname%.ini
{
  ini=`;[Settings]
  ini=%ini%`n`;lines=20   `;number of lines to show in the tray menu
  ini=%ini%`n`;watch=1    `;1=yes 0=no  watch the clipboard for urls
  ini=%ini%`n`;run=1      `;1=yes 0=no  open the clicked url in the default browser
  ini=%ini%`n`;paste=1    `;1=yes 0=no  paste the clicked url to the clipboard
  ini=%ini%`n`;comment=1  `;1=yes 0=no  add a comment to the copied url
  ini=%ini%`n
  ini=%ini%`n[Settings]
  ini=%ini%`nlines=20
  ini=%ini%`nwatch=1
  ini=%ini%`nrun=1
  ini=%ini%`npaste=1
  ini=%ini%`ncomment=1
  FileAppend,%ini%,%applicationname%.ini
  ini=
}
IniRead,lines,%applicationname%.ini,Settings,lines
IniRead,watch,%applicationname%.ini,Settings,watch
IniRead,run,%applicationname%.ini,Settings,run
IniRead,paste,%applicationname%.ini,Settings,paste
IniRead,comment,%applicationname%.ini,Settings,comment
Return


ABOUT:
Gui,99:Destroy
Gui,99:Margin,20,20
Gui,99:Add,Picture,xm Icon1,%applicationname%.exe
Gui,99:Font,Bold
Gui,99:Add,Text,x+10 yp+10,%applicationname% v1.0.1
Gui,99:Font
Gui,99:Add,Text,y+10,Copies web page addresses and titles from Internet Explorer
; Gui,99:Add,Text,y+5,- Change settings using Settings in the tray menu
Gui,99:Add,Text,y+5,- Doubleclick the tray icon to add a url and comment manually

Gui,99:Add,Text,y+10,
Gui,99:Add,Picture,xm y+20 Icon5,%applicationname%.exe
Gui,99:Font,Bold
Gui,99:Add,Text,x+10 yp+10,1 Hour Software by Skrommel
Gui,99:Font
Gui,99:Add,Text,y+10,UrlCopy is based on Skrommel's UrlHistory, available at
Gui,99:Font,CBlue Underline
Gui,99:Add,Text,y+5 G1HOURSOFTWARE,www.1HourSoftware.com
Gui,99:Font

Gui,99:Add,Picture,xm y+20 Icon7,%applicationname%.exe
Gui,99:Font,Bold
Gui,99:Add,Text,x+10 yp+10,DonationCoder
Gui,99:Font
Gui,99:Add,Text,y+10,Please support the contributors at
Gui,99:Font,CBlue Underline
Gui,99:Add,Text,y+5 GDONATIONCODER,www.DonationCoder.com
Gui,99:Font

Gui,99:Add,Picture,xm y+20 Icon6,%applicationname%.exe
Gui,99:Font,Bold
Gui,99:Add,Text,x+10 yp+10,AutoHotkey
Gui,99:Font
Gui,99:Add,Text,y+10,This tool was made using the powerful
Gui,99:Font,CBlue Underline
Gui,99:Add,Text,y+5 GAUTOHOTKEY,www.AutoHotkey.com
Gui,99:Font

Gui,99:Show,,%applicationname% About
hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
OnMessage(0x200,"WM_MOUSEMOVE")
Return

1HOURSOFTWARE:
  Run,http://www.1hoursoftware.com,,UseErrorLevel
Return

DONATIONCODER:
  Run,https://www.donationcoder.com,,UseErrorLevel
Return

AUTOHOTKEY:
  Run,http://www.autohotkey.com,,UseErrorLevel
Return

99GuiClose:
  Gui,99:Destroy
  OnMessage(0x200,"")
  DllCall("DestroyCursor","Uint",hCur)
Return

WM_MOUSEMOVE(wParam,lParam)
{
  Global hCurs
  MouseGetPos,,,,ctrl
  If ctrl in Static9,Static13,Static17
    DllCall("SetCursor","UInt",hCurs)
  Return
}
Return


EXIT:
ExitApp

Any ideas thus far?  Does anyone more knowledgeable and skilled (perhaps even Skrommel himself) want to "take this and run with it," bringing it closer to my original hopes of CopyAllUrls-like functionality?


*edit*
I did a lot of the modifications on this a while ago, before starting a "changelog."  But here's a relatively recent and very incomplete one:

0.1.3
Removed Skrommel's code that puts the URLs in the tray menu (below).  I hope this will fix the error message on extremely long URLs/titles, such as with Google Image results.
urls=
Loop,Read,%applicationname%.htm
{
  urls=%A_LoopReadLine%`n%urls%
  If (A_Index>lines)
    Break
}
Loop,Parse,urls,`n
{
  Menu,Tray,Add,%A_LoopField%,OPEN
}

0.1.2
Added a line to clear (erase) the HTML file of copied URLs when pasting!  Usually I was doing paste, clear - so why not combine the steps?  (Though this would be better as a user-defineable option, as would the shortcut keys...)

« Last Edit: February 18, 2010, 01:30 AM by Onesimus Prime »