From 41c6f232fe36dd2a52c09dae44765ea6d74d5c92 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sun, 6 Sep 2026 12:32:09 +0200 Subject: [PATCH] Fix sell on noob --- src/content-scripts/adapters/axiom.ts | 2 +- src/content-scripts/content-index.ts | 12 +++++++++--- src/content-scripts/observer.ts | 12 ++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/content-scripts/adapters/axiom.ts b/src/content-scripts/adapters/axiom.ts index 12c2316..26ece9f 100644 --- a/src/content-scripts/adapters/axiom.ts +++ b/src/content-scripts/adapters/axiom.ts @@ -29,7 +29,7 @@ function findNoobModeBuyButtons(root: ParentNode): HTMLElement[] { // Buy and Sell noob-mode buttons are siblings too; the buy one is // identified by its own text starting with "Buy", never by position. return Array.from(root.querySelectorAll('button.bg-increase')).filter((button) => - {console.log(button.textContent); return NOOB_MODE_BUY_TEXT.test(button.textContent?.trim() ?? '')}, + NOOB_MODE_BUY_TEXT.test(button.textContent?.trim() ?? ''), ); } diff --git a/src/content-scripts/content-index.ts b/src/content-scripts/content-index.ts index 00ca35e..d85074a 100644 --- a/src/content-scripts/content-index.ts +++ b/src/content-scripts/content-index.ts @@ -49,10 +49,16 @@ export function initContentScript(): void { } } - // Containers that unmounted (e.g. SPA route change) leave the DOM with - // their overlay attached; just stop tracking them, nothing to restore. for (const container of lockedContainers) { - if (!containers.has(container) && !container.isConnected) { + if (!containers.has(container)) { + // No longer a qualifying buy element — either it unmounted (SPA + // route/token change), or an in-place SPA toggle turned it into + // something else (e.g. a Buy/Sell mode switch on the same node). + // Reverse the intervention if the node is still on the page; if + // it's gone there's nothing left to restore. + if (container.isConnected) { + activeIntervention().remove(container); + } lockedContainers.delete(container); } } diff --git a/src/content-scripts/observer.ts b/src/content-scripts/observer.ts index a595b13..bc0881d 100644 --- a/src/content-scripts/observer.ts +++ b/src/content-scripts/observer.ts @@ -6,7 +6,9 @@ export interface ObserverHandle { * Generic, adapter-agnostic MutationObserver. SPA-safe: re-runs * `findElements` on every DOM mutation under `root` (rather than a one-time * querySelectorAll on load) so elements that mount/unmount client-side are - * still caught. + * still caught. Also watches class/text changes on existing nodes — some + * SPA toggles (e.g. a Buy/Sell mode switch) mutate a node in place rather + * than replacing it, which a childList-only observer would miss entirely. */ export function observeForElements( root: Node, @@ -16,7 +18,13 @@ export function observeForElements( const emit = () => onChange(findElements()); const observer = new MutationObserver(() => emit()); - observer.observe(root, { childList: true, subtree: true }); + observer.observe(root, { + childList: true, + subtree: true, + attributes: true, + attributeFilter: ['class'], + characterData: true, + }); emit();