diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-12-22 15:13:55 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-22 15:13:55 +0900 |
commit | 750be0263207b1275ae3911b5585343b49de2645 (patch) | |
tree | b635290335c2db71a6723eb7759c84bcf33a34ff | |
parent | 896c2cf60d009c9b12d99a394287cfb1d5ee1e3a (diff) | |
parent | 1c8cef7cf673deb2c3d0c5e0b3617bf2f16d7c74 (diff) |
Merge pull request #691 from ueokande/enable-addon-on-blacklisted-sites
Enable addon on blacklisted sites
-rw-r--r-- | docs/blacklist.md | 10 | ||||
-rw-r--r-- | src/content/controllers/SettingController.ts | 4 | ||||
-rw-r--r-- | src/content/usecases/KeymapUseCase.ts | 8 | ||||
-rw-r--r-- | src/shared/settings/Blacklist.ts | 5 | ||||
-rw-r--r-- | test/shared/settings/Blacklist.test.ts | 2 |
5 files changed, 14 insertions, 15 deletions
diff --git a/docs/blacklist.md b/docs/blacklist.md index 6fede63..d1db18c 100644 --- a/docs/blacklist.md +++ b/docs/blacklist.md @@ -7,20 +7,22 @@ title: Blacklist ## Blacklist The blacklist allows you to disable the plugin for certain pages by URL patterns. -For instance, you could use `"*.slack.com"` to disable the plugin on all Slack channels. -In addition, you can also specify path patterns, such as `"example.com/mail/*"`. +For instance, `"*.slack.com"` blocks the add-on on any Slack channels. +It also allows you to disable on localhost by `localhost:8000` (port is necessary). + +You can also specify path patterns to disable sites on the URL matched with the patterns. ```json { "blacklist": [ "*.slack.com", + "localhost:8000", "example.com/mail/*" ] } ``` -You can toggle Vim Vixen between disabled and enabled with -<kbd>shift</kbd>+<kbd>Esc</kbd>. +You can toggle Vim Vixen between disabled and enabled with <kbd>shift</kbd>+<kbd>Esc</kbd>. ## Partial Blacklist diff --git a/src/content/controllers/SettingController.ts b/src/content/controllers/SettingController.ts index 9124188..2d32c09 100644 --- a/src/content/controllers/SettingController.ts +++ b/src/content/controllers/SettingController.ts @@ -18,9 +18,9 @@ export default class SettingController { const url = new URL(window.location.href); const disabled = current.blacklist.includesEntireBlacklist(url); if (disabled) { - this.addonEnabledUseCase.disable(); + await this.addonEnabledUseCase.disable(); } else { - this.addonEnabledUseCase.enable(); + await this.addonEnabledUseCase.enable(); } } catch (e) { // Sometime sendMessage fails when background script is not ready. diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index 074de72..7aa7e92 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -39,16 +39,16 @@ export default class KeymapUseCase { nextOps(key: Key): { repeat: number, op: operations.Operation } | null { const sequence = this.repository.enqueueKey(key); const baseSequence = sequence.trimNumericPrefix(); + const keymaps = this.keymapEntityMap(); + const matched = keymaps.filter(([seq]) => seq.startsWith(sequence)); + const baseMatched = keymaps.filter(([seq]) => seq.startsWith(baseSequence)); + if (baseSequence.length() === 1 && this.blacklistKey(key)) { // ignore if the input starts with black list keys this.repository.clear(); return null; } - const keymaps = this.keymapEntityMap(); - const matched = keymaps.filter(([seq]) => seq.startsWith(sequence)); - const baseMatched = keymaps.filter(([seq]) => seq.startsWith(baseSequence)); - if (matched.length === 1 && sequence.length() === matched[0][0].length()) { // keys are matched with an operation diff --git a/src/shared/settings/Blacklist.ts b/src/shared/settings/Blacklist.ts index 6e6b51c..6c54d73 100644 --- a/src/shared/settings/Blacklist.ts +++ b/src/shared/settings/Blacklist.ts @@ -55,12 +55,9 @@ export class BlacklistItem { } includeKey(url: URL, key: Key): boolean { - if (!this.matches(url)) { + if (!this.matches(url) || !this.partial) { return false; } - if (!this.partial) { - return true; - } return this.keyEntities.some(k => k.equals(key)); } } diff --git a/test/shared/settings/Blacklist.test.ts b/test/shared/settings/Blacklist.test.ts index dfd036e..bcddf18 100644 --- a/test/shared/settings/Blacklist.test.ts +++ b/test/shared/settings/Blacklist.test.ts @@ -132,7 +132,7 @@ describe('Blacklist', () => { { url: 'github.com', keys: ['j', 'k'] }, ]); - expect(blacklist.includeKey(new URL('https://google.com'), Key.fromMapKey('j'))).to.be.true; + expect(blacklist.includeKey(new URL('https://google.com'), Key.fromMapKey('j'))).to.be.false; expect(blacklist.includeKey(new URL('https://github.com'), Key.fromMapKey('j'))).to.be.true; expect(blacklist.includeKey(new URL('https://github.com'), Key.fromMapKey('a'))).to.be.false; }); |