At the moment it simply notifies you (sound and traytip) when you get a new message and the traybar icon also indicates the new message count.
If you have a good idea what else I could implement, leave a post. ... I was thinking about adding Cleverbot to it to troll people. Idk.. if anyone likes the idea, I might give it a try.
v1.2 (Changelog)
Code: Select all
;<< Tray Menu
Menu, Tray, NoStandard
Menu, Tray, Add, Minimize to tray, GuiMinimizeToTray
Menu, Tray, Add, Exit, GuiClose
Menu, Tray, Default, Minimize to tray
Menu, Tray, Click, 2
Menu, Tray, Tip, WhatsApp AHK`nDouble-click to minimize
;>>
;<< Icon
If (!FileExist("WhatsApp_Gui.ico")) {
If FileExist("WhatsApp_Gui.png") {
FileDelete, WhatsApp_Gui.png
Sleep, 100
}
imgUrl := WhatsApp_GetFavIcon(0,2)
UrlDownloadToFile, % imgUrl, WhatsApp_Gui.png
MakeIco(["WhatsApp_Gui.png"])
Sleep, 10
FileDelete, WhatsApp_Gui.png
}
Menu, Tray, Icon, WhatsApp_Gui.ico
;>>
;<< Gui
Gui, 1: Add, ActiveX, x0 y0 vWB -HScroll, Shell.Explorer
Gui, Add, Button, Hidden Default gGUI_SendButton, Send
Gui, 1: +HwndMyGuiHwnd +Resize
Gui, Show, w800 h500, WhatsApp
;>>
;<< WB
ComObjConnect(WB, WB_events)
WB.silent := True
WB.Navigate("about:<!DOCTYPE html><head><meta http-equiv='X-UA-Compatible' content='IE=edge'/></head>")
WB.Navigate("https://web.whatsapp.com/",0,0,0,"User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")
Return
;>>
Class WB_events{
NewWindow3(ppDisp, cancel, dwFlags, bstrUrlContext, bstrUrl) {
NumPut(True, ComObjValue(cancel))
}
TitleChange(newTitle) {
Static oldMsgCount := 0
If (InStr(newTitle,"WhatsApp")) {
newTitle := StrReplace(newTitle, " Web", " AHK")
Gui, +LastFound
WinGetTitle, oldTitle
WinSetTitle, % newTitle
If (oldTitle != newTitle) {
RegExMatch(newTitle, "\(([^\)]+)\) WhatsApp", match)
msgCount := match1
FileDelete, WhatsApp_Tray.png
Sleep, 10
imgUrl := WhatsApp_GetFavIcon(msgCount,1)
UrlDownloadToFile, % imgUrl, WhatsApp_Tray.png
Sleep, 10
MakeIco(["WhatsApp_Tray.png"])
FileDelete, WhatsApp_Tray.png
Sleep, 10
Menu, Tray, Icon, WhatsApp_Tray.ico,,1
If (msgCount > oldMsgCount)
TrayTip, % newTitle, % "New message" (msgCount>1?"s":"") "!"
oldMsgCount := msgCount
}
}
}
}
GUI_SendButton() {
Global WB
inputs := WB.Document.getElementsByClassName("input")
Loop % inputs.length {
curInput := inputs[A_Index-1]
If (InStr(curInput.outerHTML, "placeholder=""type a message""")) {
If (curInput.innerHTML = "<br>" || curInput.innerHTML = "<br> ") {
curInput.innerHTML := ""
}
If (curInput.innerHTML != "") {
curInput.innerHTML := curInput.innerHTML
curInput.blur()
curInput.focus()
SendInput, {Space}{BS}
WB.Document.getElementsByClassName("send-container")[0].Click()
}
}
}
;}
}
GuiSize(guiHwnd, eventInfo, width, height) {
Global WB
If (eventInfo = 1)
GuiMinimizeToTray()
Else
GuiControl, Move, WB, h%height% w%width%
}
GuiMinimizeToTray() {
Gui +lastfound
WinHide
Menu, Tray, Delete, Minimize to tray
Menu, Tray, Add, Restore, Restore
Menu, Tray, Default, Restore
Menu, Tray, Tip, WhatsApp AHK`nDouble-click to restore
Menu, Tray, Delete, Exit
Menu, Tray, Add, Exit, GuiClose
;TrayTip, WhatsApp AHK, I'm still around and will keep running in the background.
}
Restore() {
Gui +lastfound
WinShow
WinRestore
WinActivate
Menu, Tray, Delete, Restore
Menu, Tray, Add, Minimize to tray, GuiMinimizeToTray
Menu, Tray, Default, Minimize to tray
Menu, Tray, Tip, WhatsApp AHK`nDouble-click to minimize
Menu, Tray, Delete, Exit
Menu, Tray, Add, Exit, GuiClose
}
GuiClose() {
ExitApp
}
WhatsApp_GetFavIcon(msgCount:=0,icoSize:=1) {
Static sizeArray := ["1x","2x"]
If (msgCount > 0)
Return "https://web.whatsapp.com/img/favicon/" sizeArray[icoSize] "/f" (msgCount<10 ? "0" msgCount : (msgCount > 99 ? "00" : msgCount)) ".png"
Else If (!msgCount)
Return "https://web.whatsapp.com/img/favicon/" sizeArray[icoSize] "/favicon.png"
Else If (msgCount < 0)
Return "https://web.whatsapp.com/img/favicon/" sizeArray[icoSize] "/favicon-error2.png"
}
MakeIco(sourceImages, icon:="") { ;Credits to kon - http://ahkscript.org/boards/viewtopic.php?p=14093#p14093
If (!icon) {
SplitPath, % sourceImages[1],, si_dir,, si_name
If (si_dir)
icon := si_dir "\" si_name ".ico"
Else
icon := si_name ".ico"
}
ICO_ContainerSize := 16
O := 0
Total_PotentialSize := 6
for i, img in sourceImages {
FileGetSize, imgSize, % img
if (imgSize)
Total_PotentialSize += ICO_ContainerSize + imgSize
}
VarSetCapacity(ICO_Data, Total_PotentialSize, 0)
NumPut(0, ICO_Data, O, "UShort"), O += 2 ;reserved - always 0
NumPut(1, ICO_Data, O, "UShort"), O += 2 ;ico = 1, cur = 2
NumPut(0, ICO_Data, O, "UShort"), O += 2 ;number of images in file (will be updated below)
For i, img in sourceImages {
dim := ImgGetDimensions(img)
width := (dim.width=256 ? 0 : dim.width)
height := (dim.height=256 ? 0 : dim.height)
If (width <= 255 && height <= 255 && File := FileOpen(img, "r")) {
NumPut(width, ICO_Data, O, "UChar"), O += 1 ;image width (256 = 0)
NumPut(height, ICO_Data, O, "UChar"), O += 1 ;image height (256 = 0)
NumPut(0, ICO_Data, O, "UChar"), O += 1 ;color palatte: 0 if not used
NumPut(0, ICO_Data, O, "UChar"), O += 1 ;reserved - always 0
NumPut(1, ICO_Data, O, "UShort"), O += 2 ;ico - color planes (0/1), cur - horizontal coordinates of the hotspot in pixels from left
NumPut(32, ICO_Data, O, "UShort"), O += 2 ;ico - bits per pixel, cur - vertical coordinates of hotspot in pixels from top
NumPut(File.Length, ICO_Data, O, "UInt"), O += 4 ;size of image data in bytes
NumPut(O + 4, ICO_Data, O, "UInt"), O += 4 ;offset of image data from begining of ico/cur file
File.RawRead(&ICO_Data + O, File.Length), O += File.Length ;actual image data
NumPut(NumGet(ICO_Data, 4, "UShort") + 1, ICO_Data, 4, "UShort") ;adds one to the total number of images
File.Close()
}
}
If (O > 6){
File := FileOpen(icon, "w")
File.RawWrite(&ICO_Data, O)
File.Close()
VarSetCapacity(ICO_Data, O, 0)
VarSetCapacity(ICO_Data, 0)
Return True
}
}
ImgGetDimensions(fileFullPath) {
dimensions := {}
RegexMatch(FileGetProperty(fileFullPath, "Height"), "(\d+)", match)
dimensions.height := match1
RegexMatch(FileGetProperty(fileFullPath, "Width"), "(\d+)", match)
dimensions.width := match1
Return dimensions
}
FileGetProperty(FilePath, Property) { ;Credits to kon - http://www.autohotkey.com/boards/viewtopic.php?f=6&t=3806
static PropTable
if (!PropTable) {
PropTable := {Name: {}, Num: {}}, Gap := 0
oShell := ComObjCreate("Shell.Application")
oFolder := oShell.NameSpace(0)
while (Gap < 11)
if (PropName := oFolder.GetDetailsOf(0, A_Index - 1)) {
PropTable.Name[PropName] := A_Index - 1
PropTable.Num[A_Index - 1] := PropName
Gap := 0
}
else
Gap++
}
If (!InStr(FilePath,":") && !InStr(FilePath,"\\"))
FilePath := A_ScriptDir "\" FilePath
if ((PropNum := PropTable.Name[Property] != "" ? PropTable.Name[Property]
: PropTable.Num[Property] ? Property : "") != "") {
SplitPath, FilePath, FileName, DirPath
oShell := ComObjCreate("Shell.Application")
oFolder := oShell.NameSpace(DirPath)
oFolderItem := oFolder.ParseName(FileName)
if (PropVal := oFolder.GetDetailsOf(oFolderItem, PropNum))
return PropVal
return 0
}
return -1
}
Spoiler
Note:
This script heavily relies on the installed version of your Internet Explorer. If your Internet Explorer version is 8 or below, this script will likely not work properly.
I am testing this script on:
AutoHotkey: 1.1.22.00, 32 Bit, Unicode
OS: Windows 8.1 Pro, x64
IE: 11.0.9600.17801