diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-05-01 15:54:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-01 15:54:31 -0400 |
commit | c514bbc4fbe39f611d7d9cfd3a48681bacbaf559 (patch) | |
tree | 275c792977b0c925fca67a324b036e1a81ba25dc /ext/js/background | |
parent | 8bf6ff92f9e318554139d3f21f1dcdb98ce59036 (diff) |
Flags profile conditions (#1647)
* Generalize modifier keys
* Optimize bindings
* Add support for flags
* Add clipboard flag
* Update tests
* Add tests
Diffstat (limited to 'ext/js/background')
-rw-r--r-- | ext/js/background/profile-conditions-util.js | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/ext/js/background/profile-conditions-util.js b/ext/js/background/profile-conditions-util.js index 928026e0..dcd60796 100644 --- a/ext/js/background/profile-conditions-util.js +++ b/ext/js/background/profile-conditions-util.js @@ -57,6 +57,17 @@ class ProfileConditionsUtil { ['notInclude', this._createSchemaModifierKeysNotInclude.bind(this)] ]) } + ], + [ + 'flags', + { + operators: new Map([ + ['are', this._createSchemaFlagsAre.bind(this)], + ['areNot', this._createSchemaFlagsAreNot.bind(this)], + ['include', this._createSchemaFlagsInclude.bind(this)], + ['notInclude', this._createSchemaFlagsNotInclude.bind(this)] + ]) + } ] ]); } @@ -121,6 +132,10 @@ class ProfileConditionsUtil { // NOP } } + const {flags} = normalizedContext; + if (!Array.isArray(flags)) { + normalizedContext.flags = []; + } return normalizedContext; } @@ -222,54 +237,76 @@ class ProfileConditionsUtil { // modifierKeys schema creation functions _createSchemaModifierKeysAre(value) { - return this._createSchemaModifierKeysGeneric(value, true, false); + return this._createSchemaArrayCheck('modifierKeys', value, true, false); } _createSchemaModifierKeysAreNot(value) { return { - not: [this._createSchemaModifierKeysGeneric(value, true, false)] + not: [this._createSchemaArrayCheck('modifierKeys', value, true, false)] }; } _createSchemaModifierKeysInclude(value) { - return this._createSchemaModifierKeysGeneric(value, false, false); + return this._createSchemaArrayCheck('modifierKeys', value, false, false); } _createSchemaModifierKeysNotInclude(value) { - return this._createSchemaModifierKeysGeneric(value, false, true); + return this._createSchemaArrayCheck('modifierKeys', value, false, true); + } + + // modifierKeys schema creation functions + + _createSchemaFlagsAre(value) { + return this._createSchemaArrayCheck('flags', value, true, false); + } + + _createSchemaFlagsAreNot(value) { + return { + not: [this._createSchemaArrayCheck('flags', value, true, false)] + }; } - _createSchemaModifierKeysGeneric(value, exact, none) { + _createSchemaFlagsInclude(value) { + return this._createSchemaArrayCheck('flags', value, false, false); + } + + _createSchemaFlagsNotInclude(value) { + return this._createSchemaArrayCheck('flags', value, false, true); + } + + // Generic + + _createSchemaArrayCheck(key, value, exact, none) { const containsList = []; - for (const modifierKey of this._split(value)) { - if (modifierKey.length === 0) { continue; } + for (const item of this._split(value)) { + if (item.length === 0) { continue; } containsList.push({ contains: { - const: modifierKey + const: item } }); } const containsListCount = containsList.length; - const modifierKeysSchema = { + const schema = { type: 'array' }; if (exact) { - modifierKeysSchema.maxItems = containsListCount; + schema.maxItems = containsListCount; } if (none) { if (containsListCount > 0) { - modifierKeysSchema.not = containsList; + schema.not = containsList; } } else { - modifierKeysSchema.minItems = containsListCount; + schema.minItems = containsListCount; if (containsListCount > 0) { - modifierKeysSchema.allOf = containsList; + schema.allOf = containsList; } } return { - required: ['modifierKeys'], + required: [key], properties: { - modifierKeys: modifierKeysSchema + [key]: schema } }; } |