brookhong / Surfingkeys

Map your keys for web surfing, expand your browser with javascript and keyboard.
https://chrome.google.com/webstore/detail/surfingkeys/gfbliohnnapiefjpjlpjnehglfpaknnc
MIT License
5.36k stars 477 forks source link

Feature to disable Surfingkeys by default #1488

Closed nchicong closed 1 year ago

nchicong commented 3 years ago

Currently Surfingkeys are enabled by default and we can disable it by shortcut Alt-S. Would there be a way to reverse this behavior like Alt-S to enable it for new tab, then Alt-S again if wanted to disable for that tab.

Thanks.

aspiers commented 2 years ago

I would like the same thing. Example use case:

On certain sites which provide a lot of their own keybindings (e.g. github.com or youtube.com), I want Surfingkeys disabled by default so that it does not interfere with the keybindings of that site. However occasionally I want to use some Surfingkey shortcut, e.g. W to move a tab to a different window. Currently this requires:

It gets messed up if I forget the last step, and also this has the unwanted side effect of temporarily enabling Surfingkeys on any other github or youtube tab I have open at the same time.

Proposed solution

Implement some inverse of both Alt-i for PassThrough mode, and p for ephemeral PassThrough, e.g. so that even when Surfingkeys is disabled:

The only catch is that these bindings would have to be carefully chosen not to conflict with any keybindings of the website, and since this applies across multiple sites, they might need to be configurable per site.

fabiomcosta commented 2 years ago

What about the having the ability to disable it based on a list of hosts? Ex: have it disabled for mail.google.com etc...

mdschmitt commented 2 years ago

@fabiomcosta Disabling Surfingkeys by default for certain sites is already possible. I believe you're looking for settings.blocklistPattern (which takes a Javascript Regex). Example:

settings.blocklistPattern = /.*stadia\\.google\\.com.*/"

Note that adding a site (or sites) to this setting does not prevent Alt-s from re-enabling SurfingKeys. If I had to guess, that's by design. ...so @nchicong this setting might solve your problem too. Disabling SK for everything might also be possible if you just wildcard everything in settigns.blocklistPattern with something like ".*", but I haven't tried that.

@aspiers If you want to disable SurfingKeys stuff for a site except for the W, you can probably use unmapAllExcept. Give it a shot? 🤷

aspiers commented 2 years ago

@aspiers If you want to disable SurfingKeys stuff for a site except for the W, you can probably use unmapAllExcept. Give it a shot? 🤷

Thanks but that's not what I want. The W was just an example of one use case.

psongers commented 2 years ago

I found out about this extension today and would like to have this behaviour. I tried this:

Note that adding a site (or sites) to this setting does not prevent Alt-s from re-enabling SurfingKeys. If I had to guess, that's by design. ...so @nchicong this setting might solve your problem too. Disabling SK for everything might also be possible if you just wildcard everything in settigns.blocklistPattern with something like ".*", but I haven't tried that.

but unfortunately it doesn't work. The hotkey runs but surfing key will always be disabled

aspiers commented 1 year ago

@brookhong Any thoughts on this? Thanks!

brookhong commented 1 year ago

@aspiers If you want to disable SurfingKeys stuff for a site except for the W, you can probably use unmapAllExcept. Give it a shot? 🤷

Thanks but that's not what I want. The W was just an example of one use case.

unmapAllExcept accepts an array as parameter, such as

unmapAllExcept(['E','R','T'], /google.com|twitter.com/);

Any other use cases?

aspiers commented 1 year ago

Oh wow, that's awesome, thanks! I didn't know it was possible to selectively map/unmap keys per site. That opens up a ton of new possibilities.

However it still doesn't really solve the problem. The challenge is finding the best way to gain immediate access to all standard SurfingKeys shortcuts and all shortcuts defined by a site. For example, here on GitHub, there are a ton of native shortcuts:

image

If I use unmapAllExcept, then for each shortcut key, I'm forced to choose between either GitHub or SurfingKeys. But I want both sets of shortcuts!

For example, gi is really useful for jumping to the GitHub issue tracker, but the g prefix key in SurfingKeys is also really useful. None of the existing approaches are perfect:

Approach Problem
unmapAllExcept Forces choice between site shortcut and SK shortcut
Use map / unmap with domain parameter Forces choice between site shortcut and SK shortcut
Use Alt-i or p for ephemeral pass-through Doesn't default to the site shortcuts
Remap SK shortcuts to other keys just for specific sites Means that you have to remember two shortcuts for each SK command. Also configuration takes a lot of work.

So I think that my previously proposed solution of an "ephemeral overlay" would still be very helpful to have.

Another way of thinking about it is as follows:

Currently, when SurfingKeys is disabled on a site (via Alt-s), then all that site's shortcuts are available, except for Alt-s which will re-enable SurfingKeys. I'm proposing that in addition to Alt-s re-enabling SK, two other key-bindings are available (in an optional and configurable way) which also re-enable SK, but only in an ephemeral manner for the current tab: Alt-i and p as described above.

brookhong commented 1 year ago

Looks like this kind of reverse mode is working partly now, please try following steps,

  1. Click the Surfingkeys icon on top right corner of your browser.
  2. Click Disable Surfingkeys x.x.x from the menu.
  3. Now you're in this kind of reverse mode.

Surfingkeys is turned off by default for every site, you can enable Surfingkeys with Alt-s only for current site. But there're two issues now,

  1. The enablement of the site is gone after page reload (but this behavior happens to be what you want).
  2. The Surfingkeys icon does not reflect its status, which means surfing keys are available though the icon is grayed out.

Regarding Alt-i or p in disable mode to enable Surfingkeys, it might confuse users considering the complexity.

aspiers commented 1 year ago

Thanks a lot for working on this! Which version adds this new behaviour? I'm on 1.1.0, and if I globally disabled it then Alt-s just generates a popup "Surfing keys is globally disabled, please enable it globally from popup menu."

However, sorry if I wasn't clear but the new behaviour described isn't quite what I was hoping for. Ideally Surfingkeys would be on by default for every site, since most sites do not offer their own key bindings. It would only make sense to have it off by default for sites like GitHub which offer their own key bindings, to avoid the conflicts. On those sites, Alt-i and p (or similar) would pass-through from the native bindings to Surfingkeys. So they would be the exact opposite of how they work when Surfingkeys is enabled. If there is a concern that this "mirrored" behaviour would confuse users, then it could be made optional instead of a default binding.

aspiers commented 1 year ago

To be clear, the main problem with the new behaviour described above is that for the majority of sites, pressing Alt-s would be required every time a site is loaded into a tab, and then the user also has to remember in which tabs they have pressed Alt-s and which still need it pressing. I think that would introduce quite a lot of friction.

egerlach commented 1 year ago

I am looking for this exact thing as well. I would love it if there were a key combo that would ephemerally enable SurfingKeys on a website when SurfingKeys is disabled. There are a few pages where I find that SurfingKeys gets in the way (Confluence page editing is the big culprit) and I just need to keep SurfingKeys disabled there or I go mad.

But then I need to jump to another page during my edit session, and I would love to be able to type <Alt-i> og How to build a widget<enter> to quickly get to a google search. When I go back to the Confluence tab I would feel more comfortable if SurfingKeys were back off so I could get back to typing. To be clear, it wouldn't need to be <Alt-i>, any key combo would do.

@brookhong, is this something I could do in my own personal config by recreating the disabled mode and overwriting it? I've remapped a number of keys but I'm not familiar enough with the API to know whether this would work or just cause chaos.

aspiers commented 1 year ago

Any more thoughts on this @brookhong?

brookhong commented 1 year ago

Ok, here is the plan.

A new mode will be introduced, which might be named as lurk, user can specify the pages where Surfingkeys will lurk until it is called out by Alt-i or p(for ephemeral case), such as

settings.lurkingPattern = /https:\/\/github\.com|.*confluence.*/i;

If the loading page matches with the lurkingPattern, Surfingkeys will enter lurk mode by default, in which mode only Alt-i and p are registered by Surfingkeys to activate normal mode. When user presses Esc or timeout, Surfingkeys reverts back to lurk mode.

The extension icon in toolbar will also be updated to reflect current status of Surfingkeys, which will be

aspiers commented 1 year ago

@brookhong This sounds perfect! Thanks so much! :heart:

aspiers commented 1 year ago

Can't wait to try this out @brookhong! Any ideas when it will be included in a new release?

brookhong commented 1 year ago

1.14.0 has been submitted to CWS, it's pending review now.

brookhong commented 1 year ago

1.14.0 has been approved and released now, please upgrade to it and try.

aspiers commented 1 year ago

@brookhong it almost works perfectly! I found a few small issues:

  1. For some reason I'm no longer seeing any statusLine popups: neither when switching from lurk to normal nor in the previous pass-through mode. (EDIT: filed as #2005)
  2. I realised that having p as the binding for ephemeral activation of normal mode isn't a good idea, because that conflicts with normal use of that key. For example, if I'm on https://github.com/brookhong/Surfingkeys with lurk mode activated, and I want to search for popup, I would expect to be able to type /popup, but that results in a search for opup because the first p gets swallowed. Maybe Alt-p would be a better binding.
  3. Having Alt-i as the binding for sticky activation of normal mode has problems too. E.g. in https://docs.google.com/ that clashes with activation of the Insert menu.
  4. Based on 3. and 4. above, I think the key-bindings for this feature need to be configurable: not just the defaults for all sites, but also with an extra option of configuring per-site for some sites. If per-site configuration is not available, that would require the user to find single key bindings to replace Alt-i and p which work on all sites, but it's impossible to guarantee that such a key binding would work on every site.
  5. When in lurk mode on https://github.com/brookhong/Surfingkeys, if I press /pp then the extension always crashes: image
brookhong commented 1 year ago

Thanks @aspiers for the findings.

The issues related with lurk mode should have been fixed in 1.15.0. p should works fine now. And to resolve the conflict of Alt-i, please try to use api.lmap to change it.

Feel free to reopen this, if there is more issue related with lurk mode.

aspiers commented 1 year ago

I don't have permissions in GitHub to reopen this issue, but I found bugs with 1.15.0:

  1. Enable lurk mode on twitter.com
  2. Set settings.showModeStatus = true;
  3. Visit twitter.com
  4. Press p ? to show SK help
  5. The status line changes to Lurk, which doesn't seem quite right
  6. Press Escape to exit SK help
  7. The status line changes to Normal, which is definitely not right, because pressing ? shows Twitter help, proving that we're actually in Lurk mode instead of normal.
  8. For further proof that the status line of Normal is wrong, press p and then wait for timeout. Now the status line changes from Normal to Lurk, which is finally correct.