Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Automatically type <sitename>@mydomain.com in Google Chrome


  • Please log in to reply
No replies to this topic
joelpt
  • Members
  • 23 posts
  • Last active: Dec 09 2011 10:05 PM
  • Joined: 24 Jun 2009
I own my own domain name and I receive all email sent to <anything>@mydomain.com. I abuse this fact when signing up on various websites, e.g. <!-- e --><a href="mailto:ebay@mydomain.com">ebay@mydomain.com</a><!-- e --> for Ebay or <!-- e --><a href="mailto:amazon@mydomain.com">amazon@mydomain.com</a><!-- e --> for Amazon. This way, when somebody sells my email address I know who did it and/or I can block email being sent to such an address if it's receiving a lot of spam.

Here's a little AHK script that will type <current site's name>@mydomain.com when I hit Win+Shift+A in Google Chrome. It sniffs the current site's address from the active Chrome tab to do this. For example, if I hit Win+Shift+A now I'd get <!-- e --><a href="mailto:autohotkey@mydomain.com">autohotkey@mydomain.com</a><!-- e -->. This makes signing up for websites using this methodology a bit faster.



;; Chrome has been seen with any of these class names
GroupAdd, GoogleChrome, ahk_class Chrome_WindowImpl_0
GroupAdd, GoogleChrome, ahk_class Chrome_WidgetWin_0
GroupAdd, GoogleChrome, ahk_class Chrome_WidgetWin_1

;; My email domain name
EmailDomainName := "mydomain.com"

;; Send sitename@mydomain.com
#IfWinActive ahk_group GoogleChrome
#+A::
    SetTitleMatchMode, Slow
    WinGetText, addr, A
    addr := RegExReplace(addr, "s).*\n(.+)", "$1")
    addr := ExtractAddress(addr)
    addr := RegExReplace(addr, "^.+\n(.+)$", "$1")
    addr := RegExReplace(addr, "^.*https?://", "")
    addr := RegExReplace(addr, "/.+$", "")
    addr := RegExReplace(addr, "(.+)\.\w+?[/\?].+?$", "$1")
    addr := RegExReplace(addr, "^(\w+)\.(\w+)\.(\w+)$", "$2")
    addr := RegExReplace(addr, "^(\w+)\.(\w+)$", "$1")
    addr := RegExReplace(addr, "^\s*(.+)\s*$", "$1")
    addr := addr . "@" . EmailDomainName

    Send %addr%
    return
#IfWinActive

;; utility functions

ExtractPath(str)
{
    ; This probably needs to be broken into a path regex and a path+filename regex, so we can
    ; do some kind of file extension check first and drop possible crap from the end of it
    output := ""
    str := RegExReplace(str, "Address:", "") ; known cleanup for Win Explorer and perhaps others (wants to match s:)
    str := " " str " "
    if (RegExMatch(str, "S)[\s\n](([a-zA-Z]:|\\\\\w+)([\\/]([\w \d\-\.]+\$?))*)", match)) ; local/UNC path
    {
        path := match1
        if (InStr(FileExist(path), "D"))
        {
            output := path "\"
        }
        else
        {
            path := RegExReplace(path, "(.+)[\\/].*", "$1")
            if (InStr(FileExist(path), "D"))
            {
                output := path "\"
            }
        }
    }
    return output
}

ExtractPathFromWindow(pattern)
{
    return ExtractPath(WinGetTitle(pattern) "`n" WinGetText(pattern))
}


;; Extracts an address from anywhere in str. 
;; Recognized addresses include URLs, email addresses, domain names, Windows local paths, and Windows UNC paths.
ExtractAddress(str)
{
  if (RegExMatch(str, "S)((http|https|ftp|mailto:)://[\S]+)", match))
    return match1
  if (RegExMatch(str, "S)(\w+@[\w.]+\.(com|net|org|gov|cc|edu|info))", match))
    return "mailto:" . match1
  if (RegExMatch(str, "S)(www\.\S+)", match))
    return "http://" . match1
  if (RegExMatch(str, "S)(\w+\.(com|net|org|gov|cc|edu|info))", match))
    return "http://" . match1
  if (RegExMatch(str, "S)([a-zA-Z]:[\\/][\\/\-_.,\d\w\s]+)", match))
    return match1
  if (RegExMatch(str, "S)(\\\\[\w\-]+\\.+)", match))
    return match1
  return ""
}

The ExtractAddress() function does more than is really needed here, but you may find it useful for other purposes.

EDIT: Fixed method so it never accidentally pulls the wrong URL from Chrome when using WinGetText.