open:hammerspoon-chrome

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


  • open/hammerspoon-chrome.txt
  • 마지막으로 수정됨: 2022/05/24 06:44
  • 저자 127.0.0.1