aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/profile-conditions.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-23 10:28:37 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-23 10:28:37 -0500
commitb4c6fa2d3747b8e938c75ab63a3783af661eca9f (patch)
treecba62ff94d02141ffa4354c55a3fd35ce51c4a05 /ext/bg/js/profile-conditions.js
parentbaf0325f628d42f382370b82e33e4c1a810050f9 (diff)
Improve usability of domain profile condition
Diffstat (limited to 'ext/bg/js/profile-conditions.js')
-rw-r--r--ext/bg/js/profile-conditions.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/ext/bg/js/profile-conditions.js b/ext/bg/js/profile-conditions.js
index 5daa904e..8272e5dd 100644
--- a/ext/bg/js/profile-conditions.js
+++ b/ext/bg/js/profile-conditions.js
@@ -17,6 +17,26 @@
*/
+function _profileConditionTestDomain(urlDomain, domain) {
+ return (
+ urlDomain.endsWith(domain) &&
+ (
+ domain.length === urlDomain.length ||
+ urlDomain[urlDomain.length - domain.length - 1] === '.'
+ )
+ );
+}
+
+function _profileConditionTestDomainList(url, domainList) {
+ const urlDomain = new URL(url).hostname.toLowerCase();
+ for (const domain of domainList) {
+ if (_profileConditionTestDomain(urlDomain, domain)) {
+ return true;
+ }
+ }
+ return false;
+}
+
const profileConditionsDescriptor = {
popupLevel: {
name: 'Popup Level',
@@ -69,7 +89,7 @@ const profileConditionsDescriptor = {
transform: (optionValue) => optionValue.split(/[,;\s]+/).map(v => v.trim().toLowerCase()).filter(v => v.length > 0),
transformReverse: (transformedOptionValue) => transformedOptionValue.join(', '),
validateTransformed: (transformedOptionValue) => (transformedOptionValue.length > 0),
- test: ({url}, transformedOptionValue) => (transformedOptionValue.indexOf(new URL(url).hostname.toLowerCase()) >= 0)
+ test: ({url}, transformedOptionValue) => _profileConditionTestDomainList(url, transformedOptionValue)
},
matchRegExp: {
name: 'Matches RegExp',