Skip to content

Commit 3dd4302

Browse files
committed
Automatically disable when the active element matches with this pattern
1 parent c3c5236 commit 3dd4302

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ Some functionalities are also available when you're using original pdf viewer, b
594594
| settings.autoSpeakOnInlineQuery | false | Whether to automatically speak the query string with TTS on inline query. |
595595
| settings.showTabIndices | false | Whether to show tab numbers (indices) in the tab titles. |
596596
| settings.tabIndicesSeparator | "\|" | The separator between index and original title of a tab. |
597+
| settings.disabledOnActiveElementPattern | undefined | Automatically disable this extension when the active element matches with this pattern and reactivate the extension when the active element changes, one useful case is to enable user to type to locate an option in a large dropdown, such as `settings.disabledOnActiveElementPattern = "ul.select-dropdown-options";` |
597598

598599
### Example of settings.theme, below is to set font size of status bar
599600

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ Surfingkeys默认使用[这个markdown分析器](https://github.com/chjj/marked)
578578
| settings.autoSpeakOnInlineQuery | false | 是否在使用inline query时自动发声。 |
579579
| settings.showTabIndices | false | 是否在标签页标题上显示当前标签页的编号。 |
580580
| settings.tabIndicesSeparator | "\|" | 标签页编号与标签页原始标题之间的分隔符。 |
581+
| settings.disabledOnActiveElementPattern | undefined | 当活动元素匹配这个设置时自动停用Surfingkeys,当活动元素变了继续启用,一个比较有用的场景是可以通过这个设置允许用户在一个大的下拉列表中通过按键快速定位选项,比如 `settings.disabledOnActiveElementPattern = "ul.select-dropdown-options";` |
581582

582583
### settings.theme示例,修改状态栏字体
583584

src/content_scripts/common/hints.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ div.hint-scrollable {
376376
dispatchMouseEvent(element, behaviours.mouseEvents, mouseEventModifiers);
377377
dispatchSKEvent("observer", ['turnOn']);
378378
lastMouseTarget = element;
379+
if (document.activeElement.matches(runtime.conf.disabledOnActiveElementPattern)) {
380+
setTimeout(() => {
381+
normal.disable(true);
382+
}, 100);
383+
}
379384
}
380385

381386
if (behaviours.multipleHits) {

src/content_scripts/common/normal.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ function createDisabled(normal) {
2424
// Disabled has higher priority than others.
2525
self.priority = 99;
2626

27+
self.activatedOnElement = false;
2728
self.addEventListener('keydown', function(event) {
2829
// prevent this event to be handled by Surfingkeys' other listeners
2930
event.sk_suppressed = true;
30-
if (Mode.isSpecialKeyOf("<Alt-s>", event.sk_keyName)) {
31+
if (self.activatedOnElement && !document.activeElement.matches(runtime.conf.disabledOnActiveElementPattern)) {
32+
normal.enable();
33+
self.activatedOnElement = false;
34+
} else if (Mode.isSpecialKeyOf("<Alt-s>", event.sk_keyName)) {
3135
normal.toggleBlocklist();
3236
self.exit();
3337
event.sk_stopPropagation = true;
@@ -963,11 +967,12 @@ function createNormal(insert) {
963967
}
964968

965969
var _disabled = null;
966-
self.disable = function() {
970+
self.disable = function(onElement) {
967971
if (!_disabled) {
968972
_disabled = createDisabled(self);
969973
_disabled.enter(0, true);
970974
}
975+
_disabled.activatedOnElement = onElement;
971976
dispatchSKEvent("observer", ['turnOff']);
972977
document.removeEventListener("mouseup", _onMouseUp);
973978
};

src/content_scripts/common/runtime.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const runtime = (function() {
4646
// local part from settings
4747
blocklistPattern: undefined,
4848
lurkingPattern: undefined,
49+
disabledOnActiveElementPattern: undefined,
4950
smartCase: true,
5051
caseSensitive: false,
5152
clickablePat: /(https?:\/\/|thunder:\/\/|magnet:)\S+/ig,

0 commit comments

Comments
 (0)