summaryrefslogtreecommitdiff
path: root/ext/js/background/profile-conditions-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/background/profile-conditions-util.js')
-rw-r--r--ext/js/background/profile-conditions-util.js67
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
}
};
}