summaryrefslogtreecommitdiff
path: root/ext/bg/js/profile-conditions.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/profile-conditions.js')
-rw-r--r--ext/bg/js/profile-conditions.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/ext/bg/js/profile-conditions.js b/ext/bg/js/profile-conditions.js
index a0710bd1..c0f5d3f5 100644
--- a/ext/bg/js/profile-conditions.js
+++ b/ext/bg/js/profile-conditions.js
@@ -36,6 +36,24 @@ function _profileConditionTestDomainList(url, domainList) {
return false;
}
+const _profileModifierKeys = [
+ {optionValue: 'alt', name: 'Alt'},
+ {optionValue: 'ctrl', name: 'Ctrl'},
+ {optionValue: 'shift', name: 'Shift'}
+];
+
+if (!hasOwn(window, 'netscape')) {
+ _profileModifierKeys.push({optionValue: 'meta', name: 'Meta'});
+}
+
+const _profileModifierValueToName = new Map(
+ _profileModifierKeys.map(({optionValue, name}) => [optionValue, name])
+);
+
+const _profileModifierNameToValue = new Map(
+ _profileModifierKeys.map(({optionValue, name}) => [name, optionValue])
+);
+
const profileConditionsDescriptor = {
popupLevel: {
name: 'Popup Level',
@@ -100,5 +118,53 @@ const profileConditionsDescriptor = {
test: ({url}, transformedOptionValue) => (transformedOptionValue !== null && transformedOptionValue.test(url))
}
}
+ },
+ modifierKeys: {
+ name: 'Modifier Keys',
+ description: 'Use profile depending on the active modifier keys.',
+ values: _profileModifierKeys,
+ defaultOperator: 'are',
+ operators: {
+ are: {
+ name: 'are',
+ placeholder: 'Press one or more modifier keys here',
+ defaultValue: '',
+ type: 'keyMulti',
+ transform: (optionValue) => optionValue
+ .split(' + ')
+ .filter((v) => v.length > 0)
+ .map((v) => _profileModifierNameToValue.get(v)),
+ transformReverse: (transformedOptionValue) => transformedOptionValue
+ .map((v) => _profileModifierValueToName.get(v))
+ .join(' + '),
+ test: ({modifierKeys}, optionValue) => areSetsEqual(new Set(modifierKeys), new Set(optionValue))
+ },
+ areNot: {
+ name: 'are not',
+ placeholder: 'Press one or more modifier keys here',
+ defaultValue: '',
+ type: 'keyMulti',
+ transform: (optionValue) => optionValue
+ .split(' + ')
+ .filter((v) => v.length > 0)
+ .map((v) => _profileModifierNameToValue.get(v)),
+ transformReverse: (transformedOptionValue) => transformedOptionValue
+ .map((v) => _profileModifierValueToName.get(v))
+ .join(' + '),
+ test: ({modifierKeys}, optionValue) => !areSetsEqual(new Set(modifierKeys), new Set(optionValue))
+ },
+ include: {
+ name: 'include',
+ type: 'select',
+ defaultValue: 'alt',
+ test: ({modifierKeys}, optionValue) => modifierKeys.includes(optionValue)
+ },
+ notInclude: {
+ name: 'don\'t include',
+ type: 'select',
+ defaultValue: 'alt',
+ test: ({modifierKeys}, optionValue) => !modifierKeys.includes(optionValue)
+ }
+ }
}
};