Fix sell on noob
This commit is contained in:
@@ -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<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() ?? ''),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user