/* This modification of the original SynonymLookup.ahk script no longer merely opens the Web page targeted with the selected word but rather downloads the source code text directly from the site. Since AutoHotkey does not need to render the Web page, it's fast while capturing the code in a variable. Next, using the RegExMatch() function to extract synonyms from the code, the script inserts each word into a pop-up menu. After selecting a word from the menu, the script replaces the original selected word in the editing field. You will find a number of useful AutoHotkey tricks described in the script below. These techniques may apply equally as well to other applications where you want to extract data from a Web page. The script requires an Internet connection to work. After selecting a word in your document, the Hotkey combination CTRL+ALT+L downloads the source code from the Web site Thesaurus.com to parse synonyms for the selected word. Find more free AutoHotkey scripts and apps at: http://www.computoredge.com/AutoHotkey/Free_AutoHotkey_Scripts_and_Apps_for_Learning_and_Generating_Ideas.html This AuoHotkey version 2.0 script uses the Hotkey combination Ctrl+Alt+Y to return a menu of synonyms. It only runs under V2.0 of AutoHotkey. AutoHotkey Version: 2.x This AutoHotkey script uses version 2.0 functions and won't run under version 1.1. The .ahk2 file extension denotes all V2.0 scripts and can be compared to the sister 1.1 scripts with the .ahk extension. For more information about how to run both V1.1 and V2.0 simultaneously, see: https://jacksautohotkeyblog.wordpress.com/2018/01/11/how-to-fool-around-with-the-new-autohotkey-version-2-0/ */ SetWorkingDir A_ScriptDir ; Ensures a consistent starting directory. ^!y:: /* The script begins with the standard Clipboard routine where the user first selects a word in any text or editing field. */ OldClipboard := ClipboardAll Clipboard:= "" Send "^c" ;copies selected text ClipWait 0 If ErrorLevel { MsgBox "No Text Selected!" Return } KeyWord := StrUpper(Clipboard) SynonymList := KeyWord ; The GetWebPage() function loads source code from the target Web into the variable SynPage. SynPage := GetWebPage("http://www.thesaurus.com/browse/" . Clipboard) Sleep 500 ; The variable NewSynPos tracks the location of each synonym as AutoHotkey looks through the Web page. ; This allows the Loop to jump to the next synonym. ; The next four lines assign the menu items as a title highlighting the selected work in all caps, ; with a bullet, and as a non-functioning default SynonymMenu := MenuCreate() SynonymMenu.Add(KeyWord, "LoadPage", "+Radio") SynonymMenu.Check(KeyWord) SynonymMenu.Default := KeyWord ; Menu, Synonym, add, %KeyWord%, LoadPage, +Radio ; Menu, Synonym, check, %KeyWord% ; Menu, Synonym, default, %KeyWord% ; The beginning of the loop which increments through the Web page variable while extracting synonyms. ;RestartLoop: NewSynPos := 1 ; The variable ItemCount increments as each synonym is added to the menu for starting new columns. ; This prevents the list from becoming too long. ItemCount := 1 Loop { ; The RegExMatch function extracts each synonym based upon unique surrounding HTML code. SynPos := RegExMatch(SynPage,"targetTerm.:.(.*?).,.targetSlug",Synonym,NewSynPos) ; SynPos := RegExMatch(SynPage,'(.*?)()(.*?)