Page 1 of 1

Add "https://" in URL if specific error page is displayed on Google Chrome

Posted: 28 Jun 2017, 07:54
by Bragato
Hi guys, first post here.
I've used AHK for a while now, started using it on Skyrim, now I use it to work with AUTOCAD and EXCEL, just basic simple macros with "Send", "Loop", etc, never used it with google chrome.

Where I work the internet access is blocked to some sites, but if I add "https://" before the site URL the access is permited, imgur always works, but it's boring to always go there and type it haha
Is there a way to automate this proccess on autohotkey?

This is the error message that displays:
http://imgur.com/WYlYrd5

With "https://":
http://imgur.com/l1znf9Q

Re: Add "https://" in URL if specific error page is displayed on Google Chrome

Posted: 28 Jun 2017, 08:37
by BoBo
Hotkey

Code: Select all

!i::Run, "<yourPathTo>\chrome.exe" "https://imgur.com" ; press Alt+i to call imgur.com
Hotstring

Code: Select all

::imgur.com::https://imgur.com ; once you type imgur.com it should replace it with https://imgur.com

Re: Add "https://" in URL if specific error page is displayed on Google Chrome

Posted: 28 Jun 2017, 08:42
by Bragato
BoBo wrote:Hotkey

Code: Select all

!i::Run, "<yourPathTo>\chrome.exe" "https://imgur.com" ; press Alt+i to call imgur.com
Hotstring

Code: Select all

::imgur.com::http://imgur.com
That should work only for imgur, I want the script to detect the error image and then add "https://" on the beginning of the URL for every site.
As I browse reddit for example, I open a reddit image on another tab and the error image is displayed, I want the script to detect that error image and add https:// to the url start so I can see the image

Re: Add "https://" in URL if specific error page is displayed on Google Chrome

Posted: 28 Jun 2017, 09:28
by BoBo
Bragatp wrote:
BoBo wrote:Hotkey

Code: Select all

!i::Run, "<yourPathTo>\chrome.exe" "https://imgur.com" ; press Alt+i to call imgur.com
Hotstring

Code: Select all

::imgur.com::http://imgur.com
That should work only for imgur, I want the script to detect the error image and then add "https://" on the beginning of the URL for every site.
As I browse reddit for example, I open a reddit image on another tab and the error image is displayed, I want the script to detect that error image and add https:// to the url start so I can see the image
Well, that wasn't said/requested in your inital post.
Best case, you provide your full requirements in the beginning.
Otherwise you end up acting like my wife :lol:

IMHO it makes sense to "correct"/pimp your entries before you call a webpage, instead of messing around how to detect a servers online response.
Let's guess your admin will get a nice salary to monitor your behaviour via the server logs and will block any variants of calling blacklisted pages sooner or later.
Good luck :)

Re: Add "https://" in URL if specific error page is displayed on Google Chrome

Posted: 28 Jun 2017, 09:33
by Bragato
BoBo wrote:
Bragatp wrote:
BoBo wrote:Hotkey

Code: Select all

!i::Run, "<yourPathTo>\chrome.exe" "https://imgur.com" ; press Alt+i to call imgur.com
Hotstring

Code: Select all

::imgur.com::http://imgur.com
That should work only for imgur, I want the script to detect the error image and then add "https://" on the beginning of the URL for every site.
As I browse reddit for example, I open a reddit image on another tab and the error image is displayed, I want the script to detect that error image and add https:// to the url start so I can see the image
Well, that wasn't said/requested in your inital post.
Best case, you provide your full requirements in the beginning.
Otherwise you end up acting like my wife :lol:
You misunderstood me, imgur was only an example of a site that works with https.
As I said, I want to automate all the proccess to type https, implied that the script must detect the error page then type https on the url

Re: Add "https://" in URL if specific error page is displayed on Google Chrome

Posted: 28 Jun 2017, 10:02
by jeeswg
This might be good, refresh a page as https://. Possible hotkey: ^F5:: (ctrl+F5). It uses the Acc library:

Code: Select all

;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

q:: ;url 'special refresh', reload page as 'https://'
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "window.client.client.client2.tool_bar2.grouping1.editable_text", 0, "ahk_id " hWnd)
vUrl := oAcc.accValue(0)
if (SubStr(vUrl, 1, 7) = "http://")
	vUrl := SubStr(vUrl, 8)
if (SubStr(vUrl, 1, 8) = "https://")
	vUrl := SubStr(vUrl, 9)
vUrl := "https://" vUrl
oAcc.accValue(0) := vUrl
;oAcc.accDoDefaultAction(0) ;didn't work
SendInput !d{Enter}
oAcc := ""
return

Re: Add "https://" in URL if specific error page is displayed on Google Chrome

Posted: 28 Jun 2017, 13:37
by Guest
jeeswg wrote:This might be good, refresh a page as https://. Possible hotkey: ^F5:: (ctrl+F5). It uses the Acc library:

Code: Select all

;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

q:: ;url 'special refresh', reload page as 'https://'
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "window.client.client.client2.tool_bar2.grouping1.editable_text", 0, "ahk_id " hWnd)
vUrl := oAcc.accValue(0)
if (SubStr(vUrl, 1, 7) = "http://")
	vUrl := SubStr(vUrl, 8)
if (SubStr(vUrl, 1, 8) = "https://")
	vUrl := SubStr(vUrl, 9)
vUrl := "https://" vUrl
oAcc.accValue(0) := vUrl
;oAcc.accDoDefaultAction(0) ;didn't work
SendInput !d{Enter}
oAcc := ""
return
Didn't work :(
When I press the hotkey the URL just gets highlighted, but nothings happens beyond that

Re: Add "https://" in URL if specific error page is displayed on Google Chrome

Posted: 28 Jun 2017, 14:41
by jeeswg
A slightly improved (logic) version of the original script, with a ToolTip line that should contain the original url (that can be commented out), and a simple version that uses the clipboard. So hopefully at least the clipboard script should work. Try AccViewer to identify the correct Acc path. Otherwise it could be possible issues like Admin windows.

[EDIT:] I've also commented out the original Acc path, and added a numeric version instead. It may be that the string version only works on English language PCs, whereas the numeric version should probably work on any PC.

Code: Select all

q:: ;url 'special refresh', reload page as 'https://'
WinGet, hWnd, ID, A
;oAcc := Acc_Get("Object", "window.client.client.client2.tool_bar2.grouping1.editable_text", 0, "ahk_id " hWnd)
oAcc := Acc_Get("Object", "4.1.2.2.3.5.2", 0, "ahk_id " hWnd)
vUrl := oAcc.accValue(0)
ToolTip, % "url: " vUrl
if (SubStr(vUrl, 1, 7) = "http://") ;http to https
	vUrl := "https://" SubStr(vUrl, 8)
else if !(SubStr(vUrl, 1, 8) = "https://") ;not http/https, prepend https
	vUrl := "https://" vUrl
oAcc.accValue(0) := vUrl
;oAcc.accDoDefaultAction(0) ;didn't work
SendInput !d{Enter}
oAcc := ""
return

;==================================================

;q:: ;url 'special refresh', reload page as 'https://'
WinGet, hWnd, ID, A
ClipSaved := ClipboardAll
Clipboard := ""
SendInput !d
Sleep 1000
SendInput ^c
ClipWait
vUrl := Clipboard
ToolTip, % "url: " vUrl
if (SubStr(vUrl, 1, 7) = "http://") ;http to https
	vUrl := "https://" SubStr(vUrl, 8)
else if !(SubStr(vUrl, 1, 8) = "https://") ;not http/https, prepend https
	vUrl := "https://" vUrl
Clipboard := vUrl
SendInput !d^v{Enter}
Clipboard := ClipSaved
return