33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
export const CALLOUT_LIMITS_STORAGE_KEY = "planet.earth.callout-limits.v1";
|
|
|
|
export function getCalloutLimits() {
|
|
try {
|
|
const raw = typeof localStorage !== "undefined" ? localStorage.getItem(CALLOUT_LIMITS_STORAGE_KEY) : null;
|
|
if (raw) {
|
|
const parsed = JSON.parse(raw);
|
|
return {
|
|
compute: Math.max(1, parseInt(parsed.compute, 10) || 1),
|
|
news: Math.max(1, parseInt(parsed.news, 10) || 1),
|
|
};
|
|
}
|
|
} catch {}
|
|
return { compute: 1, news: 1 };
|
|
}
|
|
|
|
export function setCalloutLimits(limits) {
|
|
const current = getCalloutLimits();
|
|
const next = {
|
|
compute: limits.compute != null ? Math.max(1, parseInt(limits.compute, 10)) : current.compute,
|
|
news: limits.news != null ? Math.max(1, parseInt(limits.news, 10)) : current.news,
|
|
};
|
|
try {
|
|
if (typeof localStorage !== "undefined") {
|
|
localStorage.setItem(CALLOUT_LIMITS_STORAGE_KEY, JSON.stringify(next));
|
|
}
|
|
} catch {}
|
|
if (typeof window !== "undefined") {
|
|
window.dispatchEvent(new CustomEvent("earth:callout-limits-change", { detail: next }));
|
|
}
|
|
return next;
|
|
}
|