forked from camerb/AHKs
-
Notifications
You must be signed in to change notification settings - Fork 38
/
FcnLib-GetUrlBar.ahk
73 lines (60 loc) · 2.7 KB
/
FcnLib-GetUrlBar.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include thirdParty/DDE/DDEML.ahk
;gets the contents of the url bar for firefox, iexplore, opera, or chrome
GetURLbar(browser)
{
;TODO in case the window specified does not exist, this message will be returned instead
;noSuchWindowMessage := "NO SUCH WINDOW"
noSuchWindowMessage := ""
if (browser = "chrome")
{
prevMode := A_TitleMatchMode
prevSpeed := A_TitleMatchModeSpeed
SetTitleMatchMode, RegEx
SetTitleMatchMode, Slow
WinGetText, winText, .* \- Google Chrome ahk_class Chrome_WidgetWin_1
SetTitleMatchMode, %prevMode%
SetTitleMatchMode, %prevSpeed%
;debug(wintext)
;RegExMatch(winText, "(.*)\n([^\n])", line)
;urlRegEx=(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
;RegExMatch(winText, urlRegEx, match)
RegExMatch(winText, "(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'"".,<>?«»“”‘’]))", url)
;FIXME - it appears that the URL is always on the last line, not sure
; maybe we need to use a regex to find the https, or /, or something
;StringSplit, line, winText, `n
;TODO REMOVEME - this will not work in a public lib
QuickFileOutput("browser: " . browser . "`nI think this is the url: " . url . "`n`nwintext:`n" . wintext)
return url
}
else if ( RegExMatch(browser, "^(firefox|iexplore|opera)$") )
{
;browser ;sServer := "firefox" ; iexplore, opera
sTopic := "WWW_GetWindowInfo"
sItem := "0xFFFFFFFF"
idInst := DdeInitialize()
hServer := DdeCreateStringHandle(idInst, browser)
hTopic := DdeCreateStringHandle(idInst, sTopic )
hItem := DdeCreateStringHandle(idInst, sItem )
hConv := DdeConnect(idInst, hServer, hTopic)
hData := DdeClientTransaction(0x20B0, hConv, hItem) ; XTYP_REQUEST
ddeText := DdeAccessData(hData)
DdeFreeStringHandle(idInst, hServer)
DdeFreeStringHandle(idInst, hTopic )
DdeFreeStringHandle(idInst, hItem )
DdeUnaccessData(hData)
DdeFreeDataHandle(hData)
DdeDisconnect(hConv)
DdeUninitialize(idInst)
Loop, parse, ddeText, CSV
{
returned := A_LoopField
break
}
return returned
}
else
{
returned := browser . " IS NOT A VALID OPTION FOR BROWSER PARAMETER - possible options are: firefox, chrome, iexplore, opera"
return returned
}
}