Remove part of URL from Chrome with macro/script

Get help with using AutoHotkey and its commands and hotkeys
IVerE
Posts: 4
Joined: 04 Feb 2020, 05:51

Remove part of URL from Chrome with macro/script

04 Feb 2020, 06:15

Hi!

Our network manager has implemented a rule that forbids us to go to web pages via the ad.doubleclick.net adware links that prefix many web URL's that is ads in Google Chrome. My thought was that it would be nice to simply run a AutoHotkey macro once this happens to remove the ad.doubleclick.net-part of the string and resend, since the URLs I want go to always are at the end of the URLs and can be stripped out via regex or similar.
The problem is that I am no AutoHotkey script expert and don't know how to do this.
Is this very complicated or can it be achieved relatively easy?

Here is what I want to do:
1. Jump to the browser (Chrome) address line. The Chrome pane name always ends with the text "Chrome-sok" and will also always be the current, active window
2. Mark the entire URL
3. Process it with regex_replace or similar to end up with just the end part containing the https some_url_not being the_adware-url.
4. This regex should do it: (?<=ad.doubleclick.net.*)(http.*)
5. Send a CRLF to the browser
6. Assign the above to a hotkey combo so I can press it whenever the ad.doubleclick.net warning message shows up from our servers. This could also easily be expanded to handle other adware sites by adding site|site|site etc. in the regex look-behind.

All help is grately appreciated!

Brgds
IVerE in Oslo
IVerE
Posts: 4
Joined: 04 Feb 2020, 05:51

Re: Remove part of URL from Chrome with macro/script

04 Feb 2020, 16:24

No help here so far. But I think I have managed to find a quick and easy solution by myself:

Code: Select all

^!a::
	WinWait, Personvernfeil - Google Chrome, 
	IfWinNotActive, Personvernfeil - Google Chrome, , WinActivate, Personvernfeil - Google Chrome, 
	WinWaitActive, Personvernfeil - Google Chrome, 
	MouseClick, left,  330,  61
	Sleep, 100
	Send, {CTRLDOWN}c{CTRLUP}
	Send % RegExReplace(Clipboard,"(ad\.double.*htt[p|ps]+://)","")
	Send {END}{ENTER}
return
Btw, I was wrong about the window name. It is "Personvernfeil - Google Chrome". "Personvernfeil" is Norwegian for personal protection error :-)

If anyone knows a way to get it to execute faster, that would be good. But at least I can press Ctrl-Alt-A now when the warning window comes up and it will remove the ad.doubleclick,net part of the URL-string and resend it so I get to the page I want.

Brgds
IVer in Oslo
TravisQ
Posts: 22
Joined: 17 May 2015, 23:51

Re: Remove part of URL from Chrome with macro/script

04 Feb 2020, 19:05

This is what I came up with, tested on this page. Was having problems with it working every time but seems to be stable now.
Might need tweeking.
Something here could be useful to add in. Good Luck

Code: Select all

^!a::
	save:=clipboardall
	sendinput,^l ; chrome shortcut for selecting address bar
	clipboard:=""
	sleep,100
	sendinput,^c
	clipwait
	NeedleRegEx:="(http.*)(viewtopic.*)"   ; "(?<=ad.doubleclick.net).*(http.*)"
	RegExMatch(clipboard, NeedleRegEx , OutputVar)
	clipboard:=""
	sleep,100
	clipboard:=OutputVar1
	clipwait
	sendinput,^v ;{enter}
	clipboard:=save
return
IVerE
Posts: 4
Joined: 04 Feb 2020, 05:51

Re: Remove part of URL from Chrome with macro/script

05 Feb 2020, 01:27

Thanks, TravisQ

I will certainly try your alternative approach and eventually use all or parts of it!

Thanks!

IVerE :bravo:
IVerE
Posts: 4
Joined: 04 Feb 2020, 05:51

Re: Remove part of URL from Chrome with macro/script

05 Feb 2020, 02:15

After trying and failing a bit using your suggestions, TravisQ, this is what I ended up with as the fastest and simplest way to do it:

Code: Select all

^!a::
	IfWinNotActive, Personvernfeil - Google Chrome, , WinActivate, Personvernfeil - Google Chrome, 
	IfWinNotActive, Personvernfeil - Google Chrome, , return ; If no such window is found there is no need to continue
	Send ^l ; Goto Chrome address bar and select URL
	Sleep, 10
	Send ^c ; Copy URL
	NeedleRegEx := "(ad\.double.*htt[p|ps]+://)"
	Clipboard := RegExReplace(Clipboard, NeedleRegEx, "")
	Send ^v{ENTER} ; Faster than to Send RegEx directly
return
IVerE

Return to “Ask For Help”

Who is online

Users browsing this forum: aifritz, Albireo, Bing [Bot], Eureka, GingerSpen, Google [Bot], swagfag, vsub and 238 guests