summaryrefslogtreecommitdiff
path: root/ext/bg/js/profile-conditions.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2019-12-03 18:30:22 -0800
committerAlex Yatskov <alex@foosoft.net>2019-12-03 18:30:22 -0800
commitf9ea6206550ceee625ea93215a6e08d45a750086 (patch)
tree803fe11a788a631076b3fb11a98e50bb8b454396 /ext/bg/js/profile-conditions.js
parent08ad2779678cd447bd747c2b155ef9b5135fdf5d (diff)
parent3975aabf4dc283d49ec46d0ed7ead982b9fa7441 (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/bg/js/profile-conditions.js')
-rw-r--r--ext/bg/js/profile-conditions.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/ext/bg/js/profile-conditions.js b/ext/bg/js/profile-conditions.js
index 5daa904e..ebc6680a 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',
@@ -66,10 +86,10 @@ const profileConditionsDescriptor = {
placeholder: 'Comma separated list of domains',
defaultValue: 'example.com',
transformCache: {},
- transform: (optionValue) => optionValue.split(/[,;\s]+/).map(v => v.trim().toLowerCase()).filter(v => v.length > 0),
+ 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',