feat: add beacon nexus portal slice (#167)
This commit is contained in:
67
js/utils.js
67
js/utils.js
@@ -193,6 +193,73 @@ function spellf(n) {
|
||||
return parts.join(' ') || 'zero';
|
||||
}
|
||||
|
||||
// === PORTAL HELPERS ===
|
||||
function getBeaconPortalId() {
|
||||
try {
|
||||
const search = (typeof window !== 'undefined' && window.location && typeof window.location.search === 'string')
|
||||
? window.location.search.replace(/^\?/, '')
|
||||
: '';
|
||||
if (!search) return '';
|
||||
for (const chunk of search.split('&')) {
|
||||
if (!chunk) continue;
|
||||
const [rawKey, rawValue = ''] = chunk.split('=');
|
||||
if (decodeURIComponent(rawKey || '') === 'portal') {
|
||||
return decodeURIComponent(rawValue.replace(/\+/g, ' ')).trim();
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
return '';
|
||||
}
|
||||
|
||||
function isBeaconPortalEmbed() {
|
||||
try {
|
||||
const search = (typeof window !== 'undefined' && window.location && typeof window.location.search === 'string')
|
||||
? window.location.search.replace(/^\?/, '')
|
||||
: '';
|
||||
if (!search) return false;
|
||||
for (const chunk of search.split('&')) {
|
||||
if (!chunk) continue;
|
||||
const [rawKey, rawValue = ''] = chunk.split('=');
|
||||
if (decodeURIComponent(rawKey || '') === 'embedded') {
|
||||
return decodeURIComponent(rawValue.replace(/\+/g, ' ')) === '1';
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getBeaconScopedStorageKey(baseKey) {
|
||||
const portalId = getBeaconPortalId();
|
||||
return portalId ? `${baseKey}:${portalId}` : baseKey;
|
||||
}
|
||||
|
||||
function getBeaconSaveKey() {
|
||||
return getBeaconScopedStorageKey('the-beacon-v2');
|
||||
}
|
||||
|
||||
function clearBeaconSaveAndReload() {
|
||||
try {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.removeItem(getBeaconSaveKey());
|
||||
}
|
||||
} catch (e) {}
|
||||
if (typeof location !== 'undefined' && location && typeof location.reload === 'function') {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
function applyPortalMode() {
|
||||
if (typeof document === 'undefined' || !document.body) return;
|
||||
const portalId = getBeaconPortalId();
|
||||
if (portalId) {
|
||||
document.body.setAttribute('data-portal-id', portalId);
|
||||
if (document.body.dataset) document.body.dataset.portalId = portalId;
|
||||
}
|
||||
if (isBeaconPortalEmbed()) {
|
||||
document.body.classList.add('portal-embed');
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: exportSave() and importSave() are defined in render.js (file-based).
|
||||
// The clipboard/prompt versions that were here were dead code — render.js
|
||||
// loads after utils.js and overrides them. Removed to avoid confusion.
|
||||
|
||||
Reference in New Issue
Block a user