Files
planet/frontend/public/earth/js/callout-limits.js
T
linkong c1d651589a
ci / backend (push) Has been cancelled
ci / frontend (push) Has been cancelled
ci / delivery (push) Has been cancelled
release / images (push) Has been cancelled
release: bump version to 0.76.19
2026-11-09 15:12:50 +08:00

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;
}