fix: refresh favorite identity from market bridge
This commit is contained in:
@@ -138,6 +138,7 @@ export interface CreateMarketControllerOptions {
|
||||
|
||||
const AUDIENCE_PROFILE_FIELD_SELECTION_STORAGE_KEY =
|
||||
"sces:audience-profile:selectedHeaders";
|
||||
const SERIALIZED_MARKET_ROWS_ATTRIBUTE = "data-sces-market-rows";
|
||||
|
||||
export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
const marketApiClient = createMarketApiClient();
|
||||
@@ -226,6 +227,7 @@ export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
let activeSort: MarketSortState | undefined;
|
||||
let isDisposed = false;
|
||||
let lastKnownPageSignature = "";
|
||||
let lastKnownFavoriteIdentitySignature = readFavoriteIdentitySignature(options.document);
|
||||
let needsResync = false;
|
||||
let scheduledSyncTimeoutId: number | null = null;
|
||||
let activeSyncPromise: Promise<void> | null = null;
|
||||
@@ -268,6 +270,9 @@ export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const nextFavoriteIdentitySignature = readFavoriteIdentitySignature(options.document);
|
||||
const favoriteIdentityChanged =
|
||||
nextFavoriteIdentitySignature !== lastKnownFavoriteIdentitySignature;
|
||||
|
||||
const toolbarNeedsRemount =
|
||||
!toolbar || !isPluginToolbarMounted(toolbar.root, options.document);
|
||||
@@ -291,7 +296,8 @@ export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
!needsToolbarRemount &&
|
||||
!selectionControlsMissing &&
|
||||
!favoriteControlsMissing &&
|
||||
!needsUnavailableFavoritesRecovery
|
||||
!needsUnavailableFavoritesRecovery &&
|
||||
!favoriteIdentityChanged
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -303,6 +309,10 @@ export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
if (favoriteControlsMissing || needsUnavailableFavoritesRecovery) {
|
||||
needsFavoritesRefresh = true;
|
||||
}
|
||||
if (favoriteIdentityChanged) {
|
||||
lastKnownFavoriteIdentitySignature = nextFavoriteIdentitySignature;
|
||||
needsFavoritesRefresh = true;
|
||||
}
|
||||
scheduleSync();
|
||||
});
|
||||
const observationRoot = options.document.body ?? options.document.documentElement;
|
||||
@@ -1870,10 +1880,25 @@ export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
const documentElement = options.document.documentElement;
|
||||
if (observationRoot === documentElement) {
|
||||
observer.observe(observationRoot, {
|
||||
attributeFilter: [SERIALIZED_MARKET_ROWS_ATTRIBUTE],
|
||||
attributes: true,
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
observer.observe(observationRoot, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
observer.observe(documentElement, {
|
||||
attributeFilter: [SERIALIZED_MARKET_ROWS_ATTRIBUTE],
|
||||
attributes: true
|
||||
});
|
||||
}
|
||||
|
||||
function runSyncCycle(): Promise<void> {
|
||||
@@ -1929,6 +1954,10 @@ export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
|
||||
}
|
||||
|
||||
function readFavoriteIdentitySignature(document: Document): string {
|
||||
return document.documentElement.getAttribute(SERIALIZED_MARKET_ROWS_ATTRIBUTE) ?? "";
|
||||
}
|
||||
|
||||
function readNativeToolbarActionCount(document: Document): number {
|
||||
return Array.from(document.querySelectorAll("button, a, [role='button']")).filter(
|
||||
(element) => {
|
||||
|
||||
Reference in New Issue
Block a user