evantravers / Hyper.spoon

20 stars 2 forks source link

A twist on Brave.jump #6

Open danielo515 opened 1 year ago

danielo515 commented 1 year ago

Hi there, I hope this message finds you well. Again, I wanted to express my gratitude for your work on hammerspoon. It has been a valuable resource for me and probably many others.

I am writing to share some of my modifications I believe could be interesting for others. I have updated the Brave methods to be configurable for different browsers.

Here is how it looks like

-- browser.lua
return function(browserName)
    local function open()
        hs.application.launchOrFocus(browserName)
    end
    local function jump(url)
        local script = ([[(function() {
      var browser = Application('%s');
      browser.activate();

      for (win of browser.windows()) {
        var tabIndex =
          win.tabs().findIndex(tab => tab.url().match(/%s/));

        if (tabIndex != -1) {
          win.activeTabIndex = (tabIndex + 1);
          win.index = 1;
        }
      }
    })();
  ]]):format(browserName, url)

    -- print(script)
    hs.osascript.javascript(script)
    end
    return { open = open, jump = jump }
end

And this is how it is used:

Chrome = require("browser")("Google Chrome")
Chrome.jump("localhost:3000")
evantravers commented 1 year ago

That is very cool! Would you like to make a pull request on the correct repo? I don't think that code lives in this particular repo.

danielo515 commented 1 year ago

Do you mind pointing me out to the proper repo? I only have found the browser code on this ... Oh wait, this is hyper.spoon, sorry, I thought it was the dotfiles one. In any case, I just wanted to share in case people was looking for a way to use other browsers with the great code you had for brave (it is really not easy to make the browser display the right tab)

El mié., 19 abr. 2023 22:34, Evan Travers @.***> escribió:

That is very cool! Would you like to make a pull request on the correct repo? I don't think that code lives in this particular repo.

— Reply to this email directly, view it on GitHub https://github.com/evantravers/Hyper.spoon/issues/6#issuecomment-1515343778, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWK76ASTEFJGP2OQW6LXCBD33ANCNFSM6AAAAAAXEJSQKI . You are receiving this because you authored the thread.Message ID: @.***>