SOURCE = "http://thestockmarketwatch.com/stock/?stock=$$$"; WEB_BROWSER = "C:\\BIN\\MYPAL\\mypal.exe"; WEB_BROWSER_NAME = "mypal"; SELF = WScript.ScriptFullName; CURRENT_DIRECTORY = cut(SELF, "\\", 0x10010); WshShell = WScript.CreateObject("WScript.Shell"); WordObj = WScript.CreateObject("Word.Application"); // WE USE MS-WORD ONLY TO READ NUMLOCK STATE. ABC = "\n.ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ALERT("NUMLOCK ON = RUN SCRIPT\n\nNUMLOCK OFF = STOP SCRIPT"); PAGE_SAVED = 0; INPUT_FILE = CURRENT_DIRECTORY + "\\SYMBOL_LIST.TXT"; OUTPUT_FILE = CURRENT_DIRECTORY + "\\ALLCOMPETITORS.TXT"; SYMBOLS = ReadFile(INPUT_FILE).toUpperCase(); SYMBOLS = SYMBOLS.split("\r\n"); ALERT("ABOUT TO DOWNLOAD " + SYMBOLS.length + " STOCK DATA."); for (i = 0; i < SYMBOLS.length; i++) { CURRENT_SYMBOL = Trim(SYMBOLS[i]); URL = SOURCE; URL = URL.split("$$$").join(CURRENT_SYMBOL); if (i == 0) { RUN(QUOTE(WEB_BROWSER) + " " + QUOTE(URL)); WAIT(22); WINFOCUS(WEB_BROWSER_NAME); } else { PRESS(URL); WAIT(1); PRESS("{ENTER}") WAIT(18); } PRESS("^{a}"); // SELECT ALL WAIT(1.5); PRESS("^{INSERT}"); // COPY WAIT(3); DATA = ReadClipboardText(); Process_and_Save(DATA); WAIT(1); WINFOCUS(WEB_BROWSER_NAME); PRESS("+{TAB}"); // SHIFT+TAB WAIT(0.5); PRESS("{TAB}"); // TAB WAIT(0.5); } ALERT("DONE."); EXIT(0); ////////////////////////////////////////////////// function Process_and_Save(DATA) { var ALLOWED = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 \t\n_.,<>(){}[]-+=\\|'\":;?/!`~@#$%^&*"; DATA = tr(DATA, ALLOWED); if (DATA.indexOf("Symbol Lookup") < 0) return; if (Trim(Between(DATA, "Company Profile", "Home")) == "") { SAVE_LIST = CURRENT_SYMBOL + " -\r\n\r\n"; AppendFile(OUTPUT_FILE, SAVE_LIST); return; } DATA = cut(DATA, "Learn", 0x101); DATA = cut(DATA, "Home", 0x10110); var PROFILE = cut(DATA, "Company Profile", 0x10001).split("\n").join(";"); var COMPETITORS = cut($a, "100% secure: your email is never shared, and you may opt out at any time.", 1).split("\n").join(";"); var NUMBERS = Between(DATA, "Learn", "1 day").split("\n").join(";"); var SAVE_LIST = [CURRENT_SYMBOL, PROFILE, COMPETITORS, NUMBERS].join("|") + "\r\n\r\n"; AppendFile(OUTPUT_FILE, SAVE_LIST); } ////////////////////////////////////////////////// // This function extracts a section from string S that lies between string L and R. // Returns an empty string if either L or R is not found. function Between(S, L, R, SKIP) { if (typeof(SKIP) === "undefined") SKIP = 1; var p1 = 0; for (var i = 0; i < SKIP; i++) { p1 = S.indexOf(L, p1); if (p1 < 0) return ""; p1 += L.length; } var p2 = S.indexOf(R, p1); if (p2 <= p1) return ""; return Trim(S.substring(p1, p2)); } ////////////////////////////////////////////////// // // F U N C T I O N L I B R A R Y // function Abort_Script_If_Numlock_Is_OFF() { if (GetNumlockState() == 0) EXIT(0); } function WINFOCUS(W) { Abort_Script_If_Numlock_Is_OFF(); WshShell.AppActivate(W); } function WAIT(MS) { Abort_Script_If_Numlock_Is_OFF(); MS *= 1000; WScript.Sleep(MS); Abort_Script_If_Numlock_Is_OFF(); } function RUN(CMD) { Abort_Script_If_Numlock_Is_OFF(); WshShell.Run(CMD, 9); } function SAY(TEXT) { Abort_Script_If_Numlock_Is_OFF(); var VOICE = WScript.CreateObject("SAPI.SpVoice"); VOICE.Volume = 100; VOICE.Speak(TEXT); } function EXIT(E) { WordObj.Quit(); if (typeof(E) === "undefined") E = 0; WScript.Quit(E); } function QUIT(E) { WordObj.Quit(); if (typeof(E) === "undefined") E = 0; WScript.Quit(E); } function PRESS(KEYCODE) { WAIT(0.1); WshShell.SendKeys(KEYCODE); Abort_Script_If_Numlock_Is_OFF(); } function ALERT(MSG) { WScript.Echo(MSG); } function QUOTE(S) { return '"' + S + '"'; } function DEBUG(S) { ALERT("DEBUG:|" + S + "|"); } ////////////////////////////////////////////////// // This function positions our window in the center of the screen. function CENTER(W, H) { self.resizeTo(W, H); self.moveTo(Math.round((screen.width - W) / 2), Math.round((screen.height - H) / 2)); } ////////////////////////////////////////////////// // Creates and overwrites a text file and with a string. // Return 0 on success or 1 if an error occurred. // Global variable $a will hold an error message or the // word "SUCCESS" if there were no errors. // Usage: INTEGER = CreateFile(FILENAME, STRING) // function CreateFile(FILENAME, STRING) { $a = ""; var inASCII = 0; var inUNICODE = 1; var Overwrite = 1; var Do_Not_Overwrite = 0; try { var FSO = new ActiveXObject("Scripting.FileSystemObject"); var F = FSO.CreateTextFile(FILENAME, Overwrite, inASCII); F.Write(STRING); F.Close(); $a = "SUCCESS"; return 0; } catch (e) { $a = e.message; } return 1; } // Deletes a file. Return 0 on success or an error message. function DeleteFile(FILENAME, DELETE_READONLY) { try { FSO.DeleteFile(FILENAME, DELETE_READONLY); return 0; } catch(e) { return e.message; } } ////////////////////////////////////////////////// function TYPE(TEXT) { Abort_Script_If_Numlock_Is_OFF(); var i, t; for (i = 0; i < TEXT.length; i++) { t = TEXT.charAt(i); WAIT(0.1); if (i > 5) { t = TEXT.slice(i); i = TEXT.length; } PRESS(t); } } ////////////////////////////////////////////////// /* Most ASCII characters can be represented by the character itself. E.g, the key sequence FRED can be represented by "FRED". Some special keys, such as the control keys, function keys etc are encoded in a string enclosed by {braces} See the table below Key/Character SendKey Description ~ {~} Send a tilde (~) ! {!} Send an exclamation point (!) ^ {^} Send a caret (^) + {+} Send a plus sign (+) Backspace {BACKSPACE} or {BKSP} or {BS} Send a Backspace keystroke Break {BREAK} Send a Break keystroke Caps Lock {CAPSLOCK} Press the Caps Lock Key (toggle on or off) Clear {CLEAR} Clear the field Delete {DELETE} or {DEL} Send a Delete keystroke Insert {INSERT} or {INS} Send an Insert keystroke Cursor control arrows {LEFT} / {RIGHT} / {UP} / {DOWN} Send a Left/Right/Up/Down Arrow End {END} Send an End keystroke Enter {ENTER} or ~ Send an Enter keystroke Escape {ESCAPE} Send an Esc keystroke F1 through F16 {F1} through {F16} Send a Function keystroke Help {HELP} Send a Help keystroke Home {HOME} Send a Home keystroke Numlock {NUMLOCK} Send a Num Lock keystroke Page Down Page Up {PGDN} {PGUP} Send a Page Down or Page Up keystroke Print Screen {PRTSC} Send a Print Screen keystroke Scroll lock {SCROLLLOCK} Press the Scroll lock Key (toggle on or off) TAB {TAB} Send a TAB keystroke To specify keys combined with any combination of SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following: For SHIFT prefix with + For CTRL prefix with ^ For ALT prefix with % Example ' Open notepad Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "notepad.exe", 9 ' Give Notepad time to load WScript.Sleep 500 ' Type in Hello World WshShell.SendKeys "Hello World!" WshShell.SendKeys "{ENTER}" ' Add the date WshShell.SendKeys "{F5}" */ ////////////////////////////////////////////////// // // Returns the entire contents of a text or binary file. // Usage: STRING = ReadFile(FILENAME) // function ReadFile(FILENAME) { var F, FSO, DATA = ""; try { FSO = new ActiveXObject("Scripting.FileSystemObject"); F = FSO.OpenTextFile(FILENAME, 1); DATA = F.ReadAll(); F.Close(); return DATA; } catch (e) {} return ""; } ////////////////////////////////////////////////// // This function splits string into two parts // along the first occurrence of substring. // Returns the first part if CMD is 0x10. // Returns the second part if CMD is 1. // If substring is not found, returns the original // string if CMD is 0x100. Ignores case when // CMD is 0x1000. Starts searching from end of // string when CMD is 0x10000. // function cut(STR, SUB, CMD) { if (typeof(CMD) === "undefined") CMD = 0x111; STR += ""; SUB += ""; var P; if (CMD & 0x1000) P = (CMD & 0x10000) ? STR.toUpperCase().lastIndexOf(SUB) : STR.toUpperCase().indexOf(SUB); else P = (CMD & 0x10000) ? STR.lastIndexOf(SUB) : STR.indexOf(SUB); $a = $b = ""; if (P < 0) return (CMD & 256) ? STR : ""; $a = STR.substr(0, P); $b = STR.slice(P + SUB.length); return (CMD & 16 ? $a : '') + (CMD & 1 ? $b : ''); } ////////////////////////////////////////////////// // v2021.3.15 // This function removes all characters from STR // that do not appear anywhere in CHARSET, forcing // string to be only made up of the given characters. // Example: tr("cabbage cake", " abc") --> "cabba ca" // [This function has not been optimized yet.] // Usage: STRING = tr(STRING, STRING) // function tr(STR, CHARSET) { STR += ""; STR = STR.split(""); for (var i = 0; i < STR.length; i++) if (CHARSET.indexOf(STR[i]) < 0) STR[i] = ""; return STR.join(""); } ////////////////////////////////////////////////// // v2021.3.15 // This function returns 1 when Numlock is ON. // Returns 0 when Numlock is OFF. // Usage: INTEGER = GetNumlockState() // function GetNumlockState() { return (WordObj.NumLock) & 1; } ////////////////////////////////////////////////// // v2021.3.15 // This function returns 1 if the file exists. // Returns 0 if the file doesn't exist. // Usage: INTEGER = FileExists(FILENAME) // function FileExists(FILENAME) { var FSO, E = 0; try { FSO = new ActiveXObject("Scripting.FileSystemObject"); E = FSO.FileExists(FILENAME); } catch (e) {} return E; } ////////////////////////////////////////////////// // v2021.3.16 // This function copies all text from the clipboard. // This is done by creating an Internet Explorer // document in the background that contains a form // and a textbox for input. After pasting whatever // is on the clipboard into the textarea, we can // reads its contents and return the string. // This takes about 200ms. // // Usage: STRING = ReadClipboardText() // function ReadClipboardText() { var MSIE = WScript.CreateObject("InternetExplorer.Application"); MSIE.Visible = 0; MSIE.ToolBar = 0; MSIE.StatusBar = 0; MSIE.FullScreen = 1; MSIE.Navigate("about:blank"); /* MSIE.RegisterAsDropTarget = 0; WScript.Sleep(100); MSIE.Width = 600; MSIE.Height = 400; MSIE.Left = (MSIE.document.parentWindow.screen.availWidth - MSIE.Width) / 2; MSIE.Top = (MSIE.document.parentWindow.screen.availHeight - MSIE.Height) / 2; */ var HTML = "