diff --git a/content.css b/content.css index eec06b7..beb57a0 100644 --- a/content.css +++ b/content.css @@ -61,6 +61,11 @@ html.atm-hide-dismissed .atm-card.atm-dismissed { display: none !important; } +/* Sponsored / featured listings — fully hidden */ +.atm-sponsored { + display: none !important; +} + /* --- Detail page: floating action button --- */ .atm-fab { diff --git a/content.js b/content.js index 027484e..c1eefb2 100644 --- a/content.js +++ b/content.js @@ -69,11 +69,39 @@ function extractTitle(card) { return h ? h.textContent.trim().slice(0, 200) : ""; } +// A card is "sponsored/featured" if its detail link carries +// journey=FEATURED_LISTING_JOURNEY (AutoTrader's own tagging) or it lives +// inside an explicitly sponsored container. +function isSponsoredCard(card) { + const anchors = card.querySelectorAll('a[href*="/car-details/"]'); + for (const a of anchors) { + const href = a.getAttribute("href") || ""; + if (/journey=FEATURED_LISTING_JOURNEY/i.test(href)) return true; + } + const testid = (card.getAttribute("data-testid") || "").toLowerCase(); + if (testid.includes("featured") || testid.includes("sponsor") || testid.includes("promoted")) { + return true; + } + // Walk up one level to catch wrapper markers + const parent = card.parentElement; + if (parent) { + const ptid = (parent.getAttribute("data-testid") || "").toLowerCase(); + if (ptid.includes("featured") || ptid.includes("sponsor") || ptid.includes("promoted")) { + return true; + } + } + return false; +} + function findAllCards() { // Primary selector — verified stable on autotrader.co.uk const lis = document.querySelectorAll('li[data-testid^="id-"]'); const cards = new Map(); for (const li of lis) { + if (isSponsoredCard(li)) { + li.classList.add("atm-sponsored"); + continue; + } const id = extractIdFromLi(li); if (id) cards.set(li, id); } @@ -153,8 +181,17 @@ function startObserving() { // doesn't depend on the page layout, so it's resilient to redesigns. function getDetailListingId() { - const m = location.pathname.match(/^\/car-details\/(\d+)/); - return m ? m[1] : null; + // Accept /car-details/{id}, /classifieds/advert/{id}, trailing slashes, slugs + const patterns = [ + /^\/car-details\/(\d+)/i, + /^\/classifieds\/advert\/(\d+)/i, + /\/cars?\/[^/]+\/(\d{10,})/i, + ]; + for (const re of patterns) { + const m = location.pathname.match(re); + if (m) return m[1]; + } + return null; } function extractDetailTitle() { @@ -282,6 +319,15 @@ function watchUrlChanges() { (async function init() { await loadState(); + const detailId = getDetailListingId(); + // Diagnostic log — open Firefox DevTools console to confirm detection. + // Prefixed so you can filter with "ATM" in the console. + console.log("[ATM]", { + pathname: location.pathname, + href: location.href, + detectedDetailId: detailId, + dismissedCount: Object.keys(state.dismissed).length, + }); applyPageMode(); watchUrlChanges(); })(); diff --git a/dist/autotrader-marker-0.1.1.xpi b/dist/autotrader-marker-0.1.1.xpi new file mode 100644 index 0000000..2af2b06 Binary files /dev/null and b/dist/autotrader-marker-0.1.1.xpi differ diff --git a/dist/updates.json b/dist/updates.json index 6a0672d..707e3e6 100644 --- a/dist/updates.json +++ b/dist/updates.json @@ -5,6 +5,10 @@ { "version": "0.1.0", "update_link": "https://git.nocker.cloud/tony/autotrader-marker/raw/branch/main/dist/autotrader-marker-0.1.0.xpi" + }, + { + "version": "0.1.1", + "update_link": "https://git.nocker.cloud/tony/autotrader-marker/raw/branch/main/dist/autotrader-marker-0.1.1.xpi" } ] } diff --git a/manifest.json b/manifest.json index 958b433..c143e30 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "AutoTrader Marker", - "version": "0.1.0", + "version": "0.1.1", "description": "Mark AutoTrader listings as 'not wanted' so you can spot the ones you haven't reviewed yet.", "permissions": [ "storage" diff --git a/package.json b/package.json index cff9bb7..42e3aea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "autotrader-marker", - "version": "0.1.0", + "version": "0.1.1", "private": true, "description": "Firefox extension that marks AutoTrader listings as 'not wanted'.", "scripts": {