Ejdjdososs/fable-ai
0
1(*2Copyright (c) 2015-present, Facebook, Inc.3 4This source code is licensed under the MIT license found in the5LICENSE file at6https://github.com/facebookincubator/create-react-app/blob/master/LICENSE7*)8 9property targetTab: null10property targetTabIndex: -111property targetWindow: null12property theProgram: "Google Chrome"13 14on run argv15 set theURL to item 1 of argv16 17 -- Allow requested program to be optional,18 -- default to Google Chrome19 if (count of argv) > 1 then20 set theProgram to item 2 of argv21 end if22 23 using terms from application "Google Chrome"24 tell application theProgram25 26 if (count every window) = 0 then27 make new window28 end if29 30 -- 1: Looking for tab running debugger31 -- then, Reload debugging tab if found32 -- then return33 set found to my lookupTabWithUrl(theURL)34 if found then35 set targetWindow's active tab index to targetTabIndex36 tell targetTab to reload37 tell targetWindow to activate38 set index of targetWindow to 139 return40 end if41 42 -- 2: Looking for Empty tab43 -- In case debugging tab was not found44 -- We try to find an empty tab instead45 set found to my lookupTabWithUrl("chrome://newtab/")46 if found then47 set targetWindow's active tab index to targetTabIndex48 set URL of targetTab to theURL49 tell targetWindow to activate50 return51 end if52 53 -- 3: Create new tab54 -- both debugging and empty tab were not found55 -- make a new tab with url56 tell window 157 activate58 make new tab with properties {URL:theURL}59 end tell60 end tell61 end using terms from62end run63 64-- Function:65-- Lookup tab with given url66-- if found, store tab, index, and window in properties67-- (properties were declared on top of file)68on lookupTabWithUrl(lookupUrl)69 using terms from application "Google Chrome"70 tell application theProgram71 -- Find a tab with the given url72 set found to false73 set theTabIndex to -174 repeat with theWindow in every window75 set theTabIndex to 076 repeat with theTab in every tab of theWindow77 set theTabIndex to theTabIndex + 178 if (theTab's URL as string) contains lookupUrl then79 -- assign tab, tab index, and window to properties80 set targetTab to theTab81 set targetTabIndex to theTabIndex82 set targetWindow to theWindow83 set found to true84 exit repeat85 end if86 end repeat87 88 if found then89 exit repeat90 end if91 end repeat92 end tell93 end using terms from94 return found95end lookupTabWithUrl96 