// adeater-selectors.js — All constants, config flags, and selector lists.
// Runs in the same content-script scope as adeater-utils.js, adeater-sweepers.js,
// adeater-security.js, and adeater.js (listed in order in manifest.json "js" array).

// ---------------------------------------------------------------------------
// Configuration flags
// ---------------------------------------------------------------------------
const EAT_ADS      = true;
const EAT_TRACKERS = true;
const EAT_AUTOPLAY = true;
const EAT_HEAVY    = true;
const EAT_EMPTY    = true;
const EAT_TEXT_ADS = true;
const EAT_LINKS    = true;
const EAT_POSITION = true;
const EAT_ARIA     = true;
const EAT_POPUPS   = true;

// ---------------------------------------------------------------------------
// Advanced detection feature flags
// ---------------------------------------------------------------------------
// DOM-sweep feature flags. The MAIN-world prototype blockers keep their own
// flag copies in adeater-hooks.js; the old threat-detection flags were removed
// along with that detection code.
const ENABLE_BAIT = true; // bait-ad sweeper (adeater-sweepers.js)
const ENABLE_PERF = true; // page performance metrics (adeater-security.js)

// ---------------------------------------------------------------------------
// Whitelisted domains — never eat on these sites
// ---------------------------------------------------------------------------
const WHITELIST_HOSTS = [
  "mail.google.com",
  "accounts.google.com",
  "drive.google.com",
  "docs.google.com",
  "outlook.live.com",
  "outlook.office.com",
  "bank",
  "banking",
  "paypal.com",
  "stripe.com",
  "github.com",
  "gitlab.com",
];

function isWhitelisted() {
  const host = location.hostname.toLowerCase();
  return WHITELIST_HOSTS.some((w) => host.includes(w));
}

// ---------------------------------------------------------------------------
// Safety guard constants
// ---------------------------------------------------------------------------
const SAFE_TAGS = new Set(["BODY", "HTML", "HEAD", "ARTICLE", "MAIN", "SECTION"]);
const PROTECTED_SELECTORS = "body, article, main, [role='main'], form, input, textarea, select, [contenteditable]";
const TEXT_THRESHOLD = 200;
const TABBY_FRAME_ID = "tabby-frame";

// ---------------------------------------------------------------------------
// Ad selectors (CSS selector patterns — fully MV3-legal)
// ---------------------------------------------------------------------------
const AD_SELECTORS = [
  // Google Ads
  '[id*="google_ads"]',
  '[class*="google_ads"]',
  'ins.adsbygoogle',
  // Common ad containers
  '[id*="ad-slot"]',
  '[class*="ad-slot"]',
  '[id*="advertisement"]',
  '[class*="advertisement"]',
  '[class*="ad-container"]',
  '[id*="ad-container"]',
  '[class*="ad-wrapper"]',
  '[id*="ad-wrapper"]',
  // Banners
  '[id*="banner-ad"]',
  '[class*="banner-ad"]',
  '[id*="banner_ad"]',
  '[class*="banner_ad"]',
  '[class*="bannerAd"]',
  // Sidebar / sponsored
  '[class*="sponsored"]',
  '[id*="sponsored"]',
  '[class*="sponsor"]',
  '[id*="sponsor"]',
  // Generic ad data attributes
  'div[data-ad]',
  'div[data-advertisement]',
  'div[data-ad-slot]',
  'div[data-ad-unit]',
  // Ad iframes
  'iframe[src*="doubleclick"]',
  'iframe[src*="adnxs"]',
  'iframe[src*="adsystem"]',
  'iframe[src*="adservice"]',
  'iframe[src*="adsafeprotected"]',
  'iframe[src*="criteo"]',
  'iframe[src*="casalemedia"]',
  // Ad-related IDs and classes
  '[id*="adfox"]',
  '[class*="adfox"]',
  '[id*="adriver"]',
  '[class*="adriver"]',
  '[id*="yandex_ad"]',
  '[class*="yandex_ad"]',
  '[id*="advert"]',
  '[class*="advert"]',
  // Taboola / Outbrain
  '[id*="taboola"]',
  '[class*="taboola"]',
  '[id*="outbrain"]',
  '[class*="outbrain"]',
  // Popup / overlay ads
  '[class*="popup-ad"]',
  '[id*="popup-ad"]',
  '[class*="modal-ad"]',
  '[id*="modal-ad"]',
  // Sticky ad footers / headers
  '[class*="sticky-ad"]',
  '[id*="sticky-ad"]',
  '[class*="sticky_ad"]',
  '[class*="ad-sticky"]',
  // Amazon ads
  '[id*="amazon-ad"]',
  '[class*="amazon-ad"]',
  '[id*="amazon_ad"]',
  '[class*="amazon_ad"]',
  '[class*="amzn-native"]',
  // Media.net / Contextual
  '[id*="media-net"]',
  '[class*="media-net"]',
  '[id*="media_net"]',
  // Revcontent
  '[id*="revcontent"]',
  '[class*="revcontent"]',
  '[id*="rc-widget"]',
  // Mgid
  '[id*="mgid"]',
  '[class*="mgid"]',
  '[id*="mgid_widget"]',
  // PopAds / Popunders
  '[id*="popad"]',
  '[class*="popad"]',
  '[id*="popunder"]',
  '[class*="popunder"]',
  // Adsterra
  '[id*="adsterra"]',
  '[class*="adsterra"]',
  // PropellerAds
  '[id*="propeller"]',
  '[class*="propeller"]',
  // ExoClick
  '[id*="exoclick"]',
  '[class*="exoclick"]',
  '[id*="exo-"]',
  '[class*="exo-"]',
  // AdCash
  '[id*="adcash"]',
  '[class*="adcash"]',
  // ZergNet
  '[class*="zerg"]',
  '[id*="zerg"]',
  // Skimlinks / affiliate
  '[class*="skimlinks"]',
  '[class*="affiliate"]',
  '[id*="affiliate"]',
  // Ad sizing patterns
  '[class*="ad-300"]',
  '[class*="ad-250"]',
  '[class*="ad-728"]',
  '[class*="ad-90"]',
  '[class*="ad-160"]',
  '[class*="ad-600"]',
  '[class*="ad_300"]',
  '[class*="ad_728"]',
  '[class*="ad_250"]',
  // Common ad network containers
  '[class*="adunit"]',
  '[id*="adunit"]',
  '[class*="ad-placeholder"]',
  '[id*="ad-placeholder"]',
  '[class*="ad_placeholder"]',
  '[class*="adcode"]',
  '[id*="adcode"]',
  '[class*="adblock"]',
  '[id*="adblock"]',
  // Google AdSense auto ads
  'ins.adsbygoogle[data-ad-client]',
  'ins.adsbygoogle[data-ad-slot]',
  // Video ad containers
  '[class*="video-ad"]',
  '[id*="video-ad"]',
  '[class*="video_Ad"]',
  '[class*="preroll"]',
  '[id*="preroll"]',
  '[class*="midroll"]',
  // Native ads
  '[class*="native-ad"]',
  '[id*="native-ad"]',
  '[class*="nativeAd"]',
  '[class*="native_ad"]',
  '[class*="sponsored-content"]',
  '[class*="sponsoredContent"]',
  '[class*="sponsored_post"]',
  '[class*="promo-box"]',
  '[id*="promo-box"]',
  '[class*="promoBox"]',
  // Taboola / Outbrain (extended)
  '[class*="trc_"]',
  '[id*="trc_"]',
  'div[data-item-syndicated="true"]',
  '[class*="ob_"]',
  '[id*="ob_"]',
  '[class*="ob-widget"]',
  // Popup / overlay ads (extended)
  '[class*="interstitial"]',
  '[id*="interstitial"]',
  '[class*="overlay-ad"]',
  '[id*="overlay-ad"]',
  '[class*="overlayAd"]',
  '[class*="layer-ad"]',
  '[id*="layer-ad"]',
  '[class*="layerad"]',
  // Cookie / consent walls that double as ad containers
  '[class*="consent-wall"]',
  '[class*="consent_wall"]',
  '[class*="gdpr-wall"]',
  '[class*="gdpr_banner"]',
  // Ad-related ARIA roles
  '[role="advertisement"]',
  '[role="complementary"][class*="ad"]',
];

// ---------------------------------------------------------------------------
// Tracker selectors
// ---------------------------------------------------------------------------
const TRACKER_SELECTORS = [
  // 1x1 tracking pixels
  'img[width="1"][height="1"]',
  'img[width="1px"][height="1px"]',
  // Pixel/tracking URLs
  'img[src*="pixel"]',
  'img[src*="tracking"]',
  'img[src*="analytics"]',
  'img[src*="beacon"]',
  // Facebook / Meta
  'img[src*="facebook.com/tr"]',
  'noscript img[src*="facebook"]',
  // Google Analytics
  'img[src*="google-analytics"]',
  'img[src*="googlesyndication"]',
  // Common tracking iframes
  'iframe[src*="pixel"]',
  'iframe[src*="tracking"]',
];

// ---------------------------------------------------------------------------
// Ad text keywords (used by eatByTextContent)
// ---------------------------------------------------------------------------
const AD_TEXT_KEYWORDS = [
  "sponsored", "advertisement", "advertising", "ad choices", "adchoices",
  "promoted", "announcement", "commercial", "paid content",
  "promotion", "promotional", "presented by", "brought to you by",
  "recommended for you", "you might also like", "around the web",
  "from around the web", "sponsored content", "sponsored links",
  "sponsored stories", "sponsored results", "sponsored post",
  "sponsored by", "in partnership with", "supported by",
  "native advertisement", "native ad", "advertisement",
  "continue reading", "ad feedback", "why this ad",
];

// ---------------------------------------------------------------------------
// Known ad / tracking domains (used by eatByLinkDestination)
// ---------------------------------------------------------------------------
const AD_DOMAINS = [
  // Google / DoubleClick
  "doubleclick.net", "googlesyndication.com", "googleadservices.com",
  "google-analytics.com", "googletagmanager.com", "googleads.g.doubleclick.net",
  // Major ad exchanges
  "adnxs.com", "rubiconproject.com", "openx.net", "pubmatic.com",
  "appnexus.com", "contextweb.com", "indexww.com",
  // DSPs / DMPs
  "adsrvr.org", "adsymptotic.com", "demdex.net", "krxd.net",
  "bluekai.com", "exelator.com", "turn.com", "tidaltv.com",
  "moatads.com", "ipredictive.com", "mathtag.com", "mediamath.com",
  "agkn.com", "neustar.biz",
  // Content recommendation
  "taboola.com", "outbrain.com", "zergnet.com", "revcontent.com",
  "mgid.com", "exdynsrv.com", "exosrv.com",
  // Amazon
  "amazon-adsystem.com", "aax.amazon-adsystem.com", "amazon.com/ads",
  // Affiliate networks
  "skimlinks.com", "shareasale.com", "cj.com", "rakuten.com",
  "linksynergy.com", "impactradius.com", "commissionjunction.com",
  "zanox.com", "awin.com", "tradedoubler.com", "vcommission.com",
  // Ad networks
  "media.net", "adsterra.com", "popads.net", "propellerads.com",
  "exoclick.com", "trafficfactory.biz", "clickadu.com", "adcash.com",
  "adf.ly", "adfly.com", "adultad.net", "plugrush.com",
  "juicyads.com", "advertising.com", "tribalfusion.com",
  "valueclick.com", "kontera.com", "infolinks.com",
  // Analytics / measurement
  "scorecardresearch.com", "quantserve.com", "comscore.com",
  "nr-data.net", "newrelic.com", "hotjar.com", "fullstory.com",
  "mouseflow.com", "crazyegg.com", "luckyorange.com", "clarity.ms",
  "clicktale.net", "sessioncam.com",
  // Social pixels
  "facebook.com/tr", "connect.facebook.net", "pixel.facebook.com",
  "analytics.twitter.com", "ads.linkedin.com", "bat.bing.com",
  "ads.yahoo.com", "ad.yieldmanager.com",
  // Newer / less common
  "adzerk.net", "sovrn.com", "bidswitch.net",
  "adsafeprotected.com", "casalemedia.com", "criteo.com", "criteo.net",
  "rlcdn.com", "rfihub.com", "segment.io", "segment.com",
  "mxpnl.com", "mixpanel.com", "amplitude.com",
  // Ad serving infrastructure
  "adserver.com", "adserver.net", "adsrvmedia.net",
  "adtech.de", "adtechus.com", "smartadserver.com",
  "adition.com", "adform.com", "adkernel.com",
  // Consent / CMP that serve ads
  "onetrust.com", "cookiebot.com", "consent.cookieinfo.com",
  "quantcast.mgr.consensu.org",
];

