5
STATUS UNKNOWN
/**
* SEKAI IFRAME API & PREVIEW EDITING
*/
(function setupPreviewEditingAPI() {
window.addEventListener('message', (event) => {
const msg = event.data;
if (msg?.origin !== 'sekai_gaming_iframe_api') return;
switch (msg.type) {
case 'get_editable_metadata':
window.parent.postMessage({
origin: 'sekai_gaming_iframe_api',
type: 'receive_editable_metadata',
taskId: msg.taskId,
data: window.sekaiEditable || {}
}, '*');
break;
case 'apply_change':
const success = applySingleChange(msg.data.id, msg.data.value, msg.data.name, msg.data.description);
window.parent.postMessage({
origin: 'sekai_gaming_iframe_api',
type: 'receive_apply_change',
taskId: msg.taskId,
data: { success }
}, '*');
break;
case 'get_current_html':
window.parent.postMessage({
origin: 'sekai_gaming_iframe_api',
type: 'receive_current_html',
taskId: msg.taskId,
data: { html: document.documentElement.outerHTML }
}, '*');
break;
case 'reset_changes':
location.reload();
break;
}
});
function applySingleChange(id, value, name, description) {
const categories = ['tune', 'images', 'videos', 'music', 'sfx', 'colors', 'text', 'prompts', 'voices'];
for (const cat of categories) {
const item = window.sekaiEditable[cat]?.find(i => i.id === id);
if (!item) continue;
item.value = value;
if (name) item.name = name;
if (description) item.description = description;
if (item.id === 'killer') {
appState.killerImageSrc = value;
}
if (item.cssVar) {
document.documentElement.style.setProperty(item.cssVar, value);
} else if (item.path) {
setNestedValue(window, item.path, value);
} else if (item.selector) {
const el = document.querySelector(item.selector);
if (!el) return false;
if (el.tagName === 'AUDIO') {
const wasPlaying = !el.paused;
el.src = value;
el.load();
if (wasPlaying) el.play().catch(() => {});
} else if (el.tagName === 'VIDEO') {
el.src = value;
el.load();
} else if (item.property === 'src') {
// Don't override if it's currently the transformed killer
if (!(appState.phase === 'killer' && el.id === `img-p${appState.chosenIndex+1}`)) {
el.src = value;
}
} else if (item.property === 'backgroundImage') {
el.style.backgroundImage = `url('${value}')`;
} else if (item.property === 'placeholder') {
el.placeholder = value;
} else {
el.textContent = value;
}
}
return true;
}
return false;
}
})();
// Boot
document.addEventListener('DOMContentLoaded', initApp);