ripdad Posted December 19, 2010 Posted December 19, 2010 (edited) Here's something I was playing with several months ago. Maybe someone will find a use for it. expandcollapse popup; Url2Hosts ; Date Released: December 18, 2010 by ripdad ; Tested on: WinXP Pro SP2 - Mozilla FireFox v3 - AutoIt3 v3.3.6 ; ; - Get and save current url address to file / log ; - Get all links in current page and check for "keyword" banned url's ; - Automatically writes banned "keyword" url's to hosts file if not already listed ; ; Example: Yes ; #include <array.au3>; (comment when ready) Local $ui = GUICreate('Url2Host', 150, 0, -1, -1), $title = '' GUISetState(@SW_SHOW, $ui) GUISetState(@SW_MINIMIZE, $ui) Do If WinActive('[Class:MozillaUIWindowClass]', '') And WinGetTitle('[Class:MozillaUIWindowClass]', '') <> $title Then $title = WinGetTitle('[Class:MozillaUIWindowClass]', ''); get title Sleep(200) Send('^l'); highlight address bar Sleep(200) Send('^c'); copy url Sleep(200) Url2Host(ClipGet()); run the function EndIf Until GUIGetMsg() = -3 GUIDelete($ui) Exit Func Url2Host($sURL) If Not StringInStr($sURL, 'http://') Then Return IniWrite(@ScriptDir & '\Url2Host.ini', 'FFUrls', $sURL, ''); write url to file - used ini to prevent duplication Local $HostFile = @SystemDir & '\drivers\etc\hosts' If Not FileExists($HostFile) Then Return Local $sLinks = BinaryToString(InetRead($sURL, 1)) If @error Then Return Local $aLinks = StringRegExp($sLinks, '(?i)(?s)http://(.*?)/', 3) If Not IsArray($aLinks) Then Return FileSetAttrib($HostFile, '-R') For $i = 0 To UBound($aLinks) - 1 Select; go through links for possible "keyword" match below - (examples) Case StringInStr($aLinks[$i], 'google') Case StringInStr($aLinks[$i], 'doubleclick') Case StringInStr($aLinks[$i], 'double-click') Case StringInStr($aLinks[$i], 'twitter') Case StringInStr($aLinks[$i], 'facebook') Case StringInStr($aLinks[$i], 'aol') Case StringInStr($aLinks[$i], 'bot') Case Else ContinueLoop EndSelect; if match and not in hosts file then add link to hosts file If Not StringInStr(FileRead($HostFile), $aLinks[$i]) Then ; disabled till you are sure you want to do it ;If StringLen($aLinks[$i]) < 40 Then FileWriteLine($HostFile, '127.0.0.1' & @TAB & $aLinks[$i]) EndIf; we want the primary url - not the entire link. (not foolproof) Next _ArrayDisplay($aLinks); view all links from webpage. (comment when ready) RunWait(@SystemDir & '\notepad.exe' & ' "' & $HostFile & '"'); view hosts file for possible editing. (comment when ready) ; FileSetAttrib($HostFile, '+R') EndFunc Edited December 19, 2010 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
4Eyes Posted January 6, 2011 Posted January 6, 2011 ripdad, That's a cool idea to use ctrl-l and ctrl-c to read the current address. Works for Chrome too. Gets the active tab, but not all tabs and is not automated so needs to poll, but it's better than nothing. Thanks! 4Eyes
ripdad Posted January 7, 2011 Author Posted January 7, 2011 There seems to be a transparent window across the top part of FF. Either that or the entire area is grouped together. Otherwise, I would have tried other methods like WinGetText() which failed. Also tried FF UDF, which also failed. It was probably ok with earlier versions of FF, but not the newer ones. At least I haven't found a way using it. The only thing that did work was Send('^l') and Send('^c') With a popup window .. this does not work properly. It works from the keyboard Ctrl+l and Ctrl+c but not with Send('^l') and Send('^c') Not sure why it does this. Very strange indeed. A work-around was Send('^s') to save the popup page to disk and read that way. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now