Improve usability of domain profile condition
This commit is contained in:
parent
baf0325f62
commit
b4c6fa2d37
@ -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 = {
|
const profileConditionsDescriptor = {
|
||||||
popupLevel: {
|
popupLevel: {
|
||||||
name: 'Popup Level',
|
name: 'Popup Level',
|
||||||
@ -69,7 +89,7 @@ const profileConditionsDescriptor = {
|
|||||||
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(', '),
|
transformReverse: (transformedOptionValue) => transformedOptionValue.join(', '),
|
||||||
validateTransformed: (transformedOptionValue) => (transformedOptionValue.length > 0),
|
validateTransformed: (transformedOptionValue) => (transformedOptionValue.length > 0),
|
||||||
test: ({url}, transformedOptionValue) => (transformedOptionValue.indexOf(new URL(url).hostname.toLowerCase()) >= 0)
|
test: ({url}, transformedOptionValue) => _profileConditionTestDomainList(url, transformedOptionValue)
|
||||||
},
|
},
|
||||||
matchRegExp: {
|
matchRegExp: {
|
||||||
name: 'Matches RegExp',
|
name: 'Matches RegExp',
|
||||||
|
Loading…
Reference in New Issue
Block a user