Release v0.1.1: hide sponsored listings, broaden detail-page detection
- Hide any card whose anchor carries `journey=FEATURED_LISTING_JOURNEY`
or whose container is tagged featured/sponsor/promoted.
- Detail-page URL regex now also matches `/classifieds/advert/{id}` and
`/cars/{slug}/{id}` in case AutoTrader redirects through either.
- Added a `[ATM]` console.log at init so unresolved detection issues can
be diagnosed from Firefox DevTools.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+48
-2
@@ -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();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user