aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/profile-conditions.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-05-03 04:39:24 +0300
committerGitHub <noreply@github.com>2020-05-03 04:39:24 +0300
commit77b744e675f8abf17ff5e8433f4f1717e0c9ffb5 (patch)
tree037cb5c45dc1f9041130ea913d120e7f1526b1e1 /ext/bg/js/profile-conditions.js
parentacfdaa4f483790cf3d70a2c1a59d82a422ebed1f (diff)
Modifier key profile condition (#487)
* update Frontend options on modifier change * add modifier key profile condition * use select element for modifier condition value * support "is" and "is not" modifier key conditions * use plural * remove dead null check it's never null in that function * pass element on rather than assigning to this * rename event * remove Firefox OS key to Meta detection * hide Meta from dropdown on Firefox * move input type
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)
+ }
+ }
}
};