Fix sell on noob

This commit is contained in:
2026-09-06 12:32:09 +02:00
parent 0099a6b753
commit 41c6f232fe
3 changed files with 20 additions and 6 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ function findNoobModeBuyButtons(root: ParentNode): HTMLElement[] {
// Buy and Sell noob-mode buttons are siblings too; the buy one is // Buy and Sell noob-mode buttons are siblings too; the buy one is
// identified by its own text starting with "Buy", never by position. // identified by its own text starting with "Buy", never by position.
return Array.from(root.querySelectorAll<HTMLElement>('button.bg-increase')).filter((button) => return Array.from(root.querySelectorAll<HTMLElement>('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() ?? ''),
); );
} }
+9 -3
View File
@@ -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) { 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); lockedContainers.delete(container);
} }
} }
+10 -2
View File
@@ -6,7 +6,9 @@ export interface ObserverHandle {
* Generic, adapter-agnostic MutationObserver. SPA-safe: re-runs * Generic, adapter-agnostic MutationObserver. SPA-safe: re-runs
* `findElements` on every DOM mutation under `root` (rather than a one-time * `findElements` on every DOM mutation under `root` (rather than a one-time
* querySelectorAll on load) so elements that mount/unmount client-side are * 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( export function observeForElements(
root: Node, root: Node,
@@ -16,7 +18,13 @@ export function observeForElements(
const emit = () => onChange(findElements()); const emit = () => onChange(findElements());
const observer = new MutationObserver(() => emit()); 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(); emit();