# hammperspoon chrome local module = {} module.start = function(config_table) module.config = config_table end module.jump = function(searchUrl, gotoUrl) local url= string.gsub(searchUrl, "/", "\\/") if gotoUrl == nil then gotoUrl = searchUrl end hs.osascript.javascript([[ (function() { var chrome = Application('Google Chrome'); chrome.activate(); var find = false; for (win of chrome.windows()) { var tabIndex = win.tabs().findIndex(tab => tab.url().match(/]] .. url .. [[/)); if (tabIndex != -1) { win.activeTabIndex = (tabIndex + 1); win.index = 1; find = true; } } if (!find) { chrome.includeStandardAdditions = true; chrome.openLocation("]] .. gotoUrl .. [["); //chrome.windows[0].tabs[0].url = "]] .. gotoUrl .. [["; chrome.windows[0].activeTabIndex = -1; } })(); ]]) end module.killTabsByDomain = function(domain) hs.osascript.javascript([[ (function() { var chrome = Application('Google Chrome'); for (win of chrome.windows()) { for (tab of win.tabs()) { if (tab.url().match(/]] .. string.gsub(domain, '/', '\\/') .. [[/)) { tab.close() } } } })(); ]]) end return module