src/abp-filter-parser.js
function matchOptions(parsedFilterData, input, contextParams = {}) {
  if (contextParams.elementTypeMask !== undefined && parsedFilterData.options) {
    if (parsedFilterData.options.elementTypeMask !== undefined &&
        !(parsedFilterData.options.elementTypeMask & contextParams.elementTypeMask)) {
      return false;
    } if (parsedFilterData.options.skipElementTypeMask !== undefined &&
          parsedFilterData.options.skipElementTypeMask & contextParams.elementTypeMask) {
      return false;
    }
  }

  // Domain option check
  if (contextParams.domain !== undefined && parsedFilterData.options) {
    if (parsedFilterData.options.domains || parsedFilterData.options.skipDomains) {
      // Get the domains that should be considered
      let shouldBlockDomains = parsedFilterData.options.domains.filter((domain) =>
        !isThirdPartyHost(domain, contextParams.domain));

      let shouldSkipDomains = parsedFilterData.options.skipDomains.filter((domain) =>
        !isThirdPartyHost(domain, contextParams.domain));
      // Handle cases like: example.com|~foo.example.com should llow for foo.example.com
      // But ~example.com|foo.example.com should block for foo.example.com
      let leftOverBlocking = shouldBlockDomains.filter((shouldBlockDomain) =>
        shouldSkipDomains.every((shouldSkipDomain) =>
          isThirdPartyHost(shouldBlockDomain, shouldSkipDomain)));
      let leftOverSkipping = shouldSkipDomains.filter((shouldSkipDomain) =>
        shouldBlockDomains.every((shouldBlockDomain) =>
          isThirdPartyHost(shouldSkipDomain, shouldBlockDomain)));

      // If we have none left over, then we shouldn't consider this a match
      if (shouldBlockDomains.length === 0 && parsedFilterData.options.domains.length !== 0 ||
          shouldBlockDomains.length > 0 && leftOverBlocking.length === 0 ||
          shouldSkipDomains.length > 0 && leftOverSkipping.length > 0) {
        return false;
      }
    }
  }

  // If we're in the context of third-party site, then consider third-party option checks
  if (contextParams['third-party'] !== undefined) {
    // Is the current rule check for third party only?
    if (filterDataContainsOption(parsedFilterData, 'third-party')) {
      let inputHost = getUrlHost(input);
      let inputHostIsThirdParty = isThirdPartyHost(parsedFilterData.host, inputHost);
      if (inputHostIsThirdParty || !contextParams['third-party']) {
        return false;
      }
    }
  }

  return true;
}
function matchOptions(parsedFilterData, input, contextParams = {}) {
  if (contextParams.elementTypeMask !== undefined && parsedFilterData.options) {
    if (parsedFilterData.options.elementTypeMask !== undefined &&
        !(parsedFilterData.options.elementTypeMask & contextParams.elementTypeMask)) {
      return false;
    } if (parsedFilterData.options.skipElementTypeMask !== undefined &&
          parsedFilterData.options.skipElementTypeMask & contextParams.elementTypeMask) {
      return false;
    }
  }

  // Domain option check
  if (contextParams.domain !== undefined && parsedFilterData.options) {
    if (parsedFilterData.options.domains || parsedFilterData.options.skipDomains) {
      // Get the domains that should be considered
      let shouldBlockDomains = parsedFilterData.options.domains.filter((domain) =>
        !isThirdPartyHost(domain, contextParams.domain));

      let shouldSkipDomains = parsedFilterData.options.skipDomains.filter((domain) =>
        !isThirdPartyHost(domain, contextParams.domain));
      // Handle cases like: example.com|~foo.example.com should llow for foo.example.com
      // But ~example.com|foo.example.com should block for foo.example.com
      let leftOverBlocking = shouldBlockDomains.filter((shouldBlockDomain) =>
        shouldSkipDomains.every((shouldSkipDomain) =>
          isThirdPartyHost(shouldBlockDomain, shouldSkipDomain)));
      let leftOverSkipping = shouldSkipDomains.filter((shouldSkipDomain) =>
        shouldBlockDomains.every((shouldBlockDomain) =>
          isThirdPartyHost(shouldSkipDomain, shouldBlockDomain)));

      // If we have none left over, then we shouldn't consider this a match
      if (shouldBlockDomains.length === 0 && parsedFilterData.options.domains.length !== 0 ||
          shouldBlockDomains.length > 0 && leftOverBlocking.length === 0 ||
          shouldSkipDomains.length > 0 && leftOverSkipping.length > 0) {
        return false;
      }
    }
  }

  // If we're in the context of third-party site, then consider third-party option checks
  if (contextParams['third-party'] !== undefined) {
    // Is the current rule check for third party only?
    if (filterDataContainsOption(parsedFilterData, 'third-party')) {
      let inputHost = getUrlHost(input);
      let inputHostIsThirdParty = isThirdPartyHost(parsedFilterData.host, inputHost);
      if (inputHostIsThirdParty || !contextParams['third-party']) {
        return false;
      }
    }
  }

  return true;
}
function matchOptions ( parsedFilterData , input , contextParams = { } ) { if ( contextParams . elementTypeMask !== undefined && parsedFilterData . options ) { if ( parsedFilterData . options . elementTypeMask !== undefined && ! ( parsedFilterData . options . elementTypeMask & contextParams . elementTypeMask ) ) { return false ; } if ( parsedFilterData . options . skipElementTypeMask !== undefined && parsedFilterData . options . skipElementTypeMask & contextParams . elementTypeMask ) { return false ; } } // Domain option check if ( contextParams . domain !== undefined && parsedFilterData . options ) { if ( parsedFilterData . options . domains || parsedFilterData . options . skipDomains ) { // Get the domains that should be considered let shouldBlockDomains = parsedFilterData . options . domains . filter ( ( domain ) => ! isThirdPartyHost ( domain , contextParams . domain ) ) ; let shouldSkipDomains = parsedFilterData . options . skipDomains . filter ( ( domain ) => ! isThirdPartyHost ( domain , contextParams . domain ) ) ; // Handle cases like: example.com|~foo.example.com should llow for foo.example.com // But ~example.com|foo.example.com should block for foo.example.com let leftOverBlocking = shouldBlockDomains . filter ( ( shouldBlockDomain ) => shouldSkipDomains . every ( ( shouldSkipDomain ) => isThirdPartyHost ( shouldBlockDomain , shouldSkipDomain ) ) ) ; let leftOverSkipping = shouldSkipDomains . filter ( ( shouldSkipDomain ) => shouldBlockDomains . every ( ( shouldBlockDomain ) => isThirdPartyHost ( shouldSkipDomain , shouldBlockDomain ) ) ) ; // If we have none left over, then we shouldn't consider this a match if ( shouldBlockDomains . length === 0 && parsedFilterData . options . domains . length !== 0 || shouldBlockDomains . length > 0 && leftOverBlocking . length === 0 || shouldSkipDomains . length > 0 && leftOverSkipping . length > 0 ) { return false ; } } } // If we're in the context of third-party site, then consider third-party option checks if ( contextParams [ 'third-party' ] !== undefined ) { // Is the current rule check for third party only? if ( filterDataContainsOption ( parsedFilterData , 'third-party' ) ) { let inputHost = getUrlHost ( input ) ; let inputHostIsThirdParty = isThirdPartyHost ( parsedFilterData . host , inputHost ) ; if ( inputHostIsThirdParty || ! contextParams [ 'third-party' ] ) { return false ; } } } return true ; }
Determines if there's a match based on the options, this doesn't mean that the filter rule shoudl be accepted, just that the filter rule should be considered given the current context. By specifying context params, you can filter out the number of rules which are considered.
Determines if there s a match based on the options this doesn t mean that the filter rule shoudl be accepted just that the filter rule should be considered given the current context . By specifying context params you can filter out the number of rules which are considered .