fix: persist story-summary relationships and sync local changes
This commit is contained in:
101
index.js
101
index.js
@@ -55,7 +55,7 @@ if (settings.dynamicPrompt && !settings.fourthWall) settings.fourthWall = settin
|
||||
|
||||
const DEPRECATED_KEYS = [
|
||||
'characterUpdater',
|
||||
'promptSections',
|
||||
'promptSections',
|
||||
'promptPresets',
|
||||
'relationshipGuidelines',
|
||||
'scriptAssistant'
|
||||
@@ -64,7 +64,7 @@ const DEPRECATED_KEYS = [
|
||||
function cleanupDeprecatedData() {
|
||||
const s = extension_settings[EXT_ID];
|
||||
if (!s) return;
|
||||
|
||||
|
||||
let cleaned = false;
|
||||
for (const key of DEPRECATED_KEYS) {
|
||||
if (key in s) {
|
||||
@@ -73,7 +73,7 @@ function cleanupDeprecatedData() {
|
||||
console.log(`[LittleWhiteBox] Cleaned deprecated data: ${key}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (cleaned) {
|
||||
saveSettingsDebounced();
|
||||
console.log('[LittleWhiteBox] Deprecated data cleanup complete');
|
||||
@@ -194,13 +194,13 @@ function addUpdateDownloadButton() {
|
||||
totalSwitchDivider.style.display = 'flex';
|
||||
totalSwitchDivider.style.alignItems = 'center';
|
||||
totalSwitchDivider.style.justifyContent = 'flex-start';
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
totalSwitchDivider.appendChild(updateButton);
|
||||
try {
|
||||
if (window.setupUpdateButtonInSettings) {
|
||||
window.setupUpdateButtonInSettings();
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
function removeAllUpdateNotices() {
|
||||
@@ -218,7 +218,7 @@ async function performExtensionUpdateCheck() {
|
||||
if (versionData && versionData.isUpToDate === false) {
|
||||
updateExtensionHeaderWithUpdateNotice();
|
||||
}
|
||||
} catch (error) {}
|
||||
} catch (error) { }
|
||||
}
|
||||
|
||||
function registerModuleCleanup(moduleName, cleanupFunction) {
|
||||
@@ -228,26 +228,26 @@ function registerModuleCleanup(moduleName, cleanupFunction) {
|
||||
function removeSkeletonStyles() {
|
||||
try {
|
||||
document.querySelectorAll('.xiaobaix-skel').forEach(el => {
|
||||
try { el.remove(); } catch (e) {}
|
||||
try { el.remove(); } catch (e) { }
|
||||
});
|
||||
document.getElementById('xiaobaix-skeleton-style')?.remove();
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
function cleanupAllResources() {
|
||||
try {
|
||||
EventCenter.cleanupAll();
|
||||
} catch (e) {}
|
||||
try { window.xbDebugPanelClose?.(); } catch (e) {}
|
||||
} catch (e) { }
|
||||
try { window.xbDebugPanelClose?.(); } catch (e) { }
|
||||
moduleCleanupFunctions.forEach((cleanupFn) => {
|
||||
try {
|
||||
cleanupFn();
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
});
|
||||
moduleCleanupFunctions.clear();
|
||||
try {
|
||||
cleanupRenderer();
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
document.querySelectorAll('.memory-button, .mes_history_preview').forEach(btn => btn.remove());
|
||||
document.querySelectorAll('#message_preview_btn').forEach(btn => {
|
||||
if (btn instanceof HTMLElement) {
|
||||
@@ -295,11 +295,11 @@ function toggleSettingsControls(enabled) {
|
||||
async function toggleAllFeatures(enabled) {
|
||||
if (enabled) {
|
||||
toggleSettingsControls(true);
|
||||
try { window.XB_applyPrevStates && window.XB_applyPrevStates(); } catch (e) {}
|
||||
try { window.XB_applyPrevStates && window.XB_applyPrevStates(); } catch (e) { }
|
||||
saveSettingsDebounced();
|
||||
initRenderer();
|
||||
try { initVarCommands(); } catch (e) {}
|
||||
try { initVareventEditor(); } catch (e) {}
|
||||
try { initVarCommands(); } catch (e) { }
|
||||
try { initVareventEditor(); } catch (e) { }
|
||||
if (extension_settings[EXT_ID].tasks?.enabled) {
|
||||
await initTasks();
|
||||
}
|
||||
@@ -327,29 +327,29 @@ async function toggleAllFeatures(enabled) {
|
||||
try {
|
||||
if (isXiaobaixEnabled && settings.wrapperIframe && !document.getElementById('xb-callgen'))
|
||||
document.head.appendChild(Object.assign(document.createElement('script'), { id: 'xb-callgen', type: 'module', src: `${extensionFolderPath}/bridges/call-generate-service.js` }));
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
try {
|
||||
if (isXiaobaixEnabled && !document.getElementById('xb-worldbook'))
|
||||
document.head.appendChild(Object.assign(document.createElement('script'), { id: 'xb-worldbook', type: 'module', src: `${extensionFolderPath}/bridges/worldbook-bridge.js` }));
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
document.dispatchEvent(new CustomEvent('xiaobaixEnabledChanged', { detail: { enabled: true } }));
|
||||
$(document).trigger('xiaobaix:enabled:toggle', [true]);
|
||||
} else {
|
||||
try { window.XB_captureAndStoreStates && window.XB_captureAndStoreStates(); } catch (e) {}
|
||||
try { window.XB_captureAndStoreStates && window.XB_captureAndStoreStates(); } catch (e) { }
|
||||
cleanupAllResources();
|
||||
if (window.messagePreviewCleanup) try { window.messagePreviewCleanup(); } catch (e) {}
|
||||
if (window.fourthWallCleanup) try { window.fourthWallCleanup(); } catch (e) {}
|
||||
if (window.buttonCollapseCleanup) try { window.buttonCollapseCleanup(); } catch (e) {}
|
||||
try { cleanupVariablesPanel(); } catch (e) {}
|
||||
try { cleanupVariablesCore(); } catch (e) {}
|
||||
try { cleanupVarCommands(); } catch (e) {}
|
||||
try { cleanupVareventEditor(); } catch (e) {}
|
||||
try { cleanupNovelDraw(); } catch (e) {}
|
||||
try { cleanupTts(); } catch (e) {}
|
||||
try { clearBlobCaches(); } catch (e) {}
|
||||
if (window.messagePreviewCleanup) try { window.messagePreviewCleanup(); } catch (e) { }
|
||||
if (window.fourthWallCleanup) try { window.fourthWallCleanup(); } catch (e) { }
|
||||
if (window.buttonCollapseCleanup) try { window.buttonCollapseCleanup(); } catch (e) { }
|
||||
try { cleanupVariablesPanel(); } catch (e) { }
|
||||
try { cleanupVariablesCore(); } catch (e) { }
|
||||
try { cleanupVarCommands(); } catch (e) { }
|
||||
try { cleanupVareventEditor(); } catch (e) { }
|
||||
try { cleanupNovelDraw(); } catch (e) { }
|
||||
try { cleanupTts(); } catch (e) { }
|
||||
try { clearBlobCaches(); } catch (e) { }
|
||||
toggleSettingsControls(false);
|
||||
try { window.cleanupWorldbookHostBridge && window.cleanupWorldbookHostBridge(); document.getElementById('xb-worldbook')?.remove(); } catch (e) {}
|
||||
try { window.cleanupCallGenerateHostBridge && window.cleanupCallGenerateHostBridge(); document.getElementById('xb-callgen')?.remove(); } catch (e) {}
|
||||
try { window.cleanupWorldbookHostBridge && window.cleanupWorldbookHostBridge(); document.getElementById('xb-worldbook')?.remove(); } catch (e) { }
|
||||
try { window.cleanupCallGenerateHostBridge && window.cleanupCallGenerateHostBridge(); document.getElementById('xb-callgen')?.remove(); } catch (e) { }
|
||||
document.dispatchEvent(new CustomEvent('xiaobaixEnabledChanged', { detail: { enabled: false } }));
|
||||
$(document).trigger('xiaobaix:enabled:toggle', [false]);
|
||||
}
|
||||
@@ -398,13 +398,13 @@ async function setupSettings() {
|
||||
if (!isXiaobaixEnabled) return;
|
||||
const enabled = $(this).prop('checked');
|
||||
if (!enabled && key === 'fourthWall') {
|
||||
try { fourthWallCleanup(); } catch (e) {}
|
||||
try { fourthWallCleanup(); } catch (e) { }
|
||||
}
|
||||
if (!enabled && key === 'novelDraw') {
|
||||
try { cleanupNovelDraw(); } catch (e) {}
|
||||
try { cleanupNovelDraw(); } catch (e) { }
|
||||
}
|
||||
if (!enabled && key === 'tts') {
|
||||
try { cleanupTts(); } catch (e) {}
|
||||
try { cleanupTts(); } catch (e) { }
|
||||
}
|
||||
settings[key] = extension_settings[EXT_ID][key] || {};
|
||||
settings[key].enabled = enabled;
|
||||
@@ -463,7 +463,7 @@ async function setupSettings() {
|
||||
settings.wrapperIframe
|
||||
? (!document.getElementById('xb-callgen') && document.head.appendChild(Object.assign(document.createElement('script'), { id: 'xb-callgen', type: 'module', src: `${extensionFolderPath}/bridges/call-generate-service.js` })))
|
||||
: (window.cleanupCallGenerateHostBridge && window.cleanupCallGenerateHostBridge(), document.getElementById('xb-callgen')?.remove());
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
});
|
||||
|
||||
$("#xiaobaix_render_enabled").prop("checked", settings.renderEnabled !== false).on("change", async function () {
|
||||
@@ -474,7 +474,7 @@ async function setupSettings() {
|
||||
if (!settings.renderEnabled && wasEnabled) {
|
||||
cleanupRenderer();
|
||||
} else if (settings.renderEnabled && !wasEnabled) {
|
||||
initRenderer();
|
||||
initRenderer();
|
||||
setTimeout(() => processExistingMessages(), 100);
|
||||
}
|
||||
});
|
||||
@@ -494,7 +494,7 @@ async function setupSettings() {
|
||||
$(this).val(v);
|
||||
settings.maxRenderedMessages = v;
|
||||
saveSettingsDebounced();
|
||||
try { shrinkRenderedWindowFull(); } catch (e) {}
|
||||
try { shrinkRenderedWindowFull(); } catch (e) { }
|
||||
});
|
||||
|
||||
$(document).off('click.xbreset', '#xiaobaix_reset_btn').on('click.xbreset', '#xiaobaix_reset_btn', function (e) {
|
||||
@@ -519,16 +519,16 @@ async function setupSettings() {
|
||||
const el = document.getElementById(id);
|
||||
if (el) {
|
||||
el.checked = !!val;
|
||||
try { $(el).trigger('change'); } catch {}
|
||||
try { $(el).trigger('change'); } catch { }
|
||||
}
|
||||
}
|
||||
ON.forEach(k => setChecked(MAP[k], true));
|
||||
OFF.forEach(k => setChecked(MAP[k], false));
|
||||
setChecked('xiaobaix_use_blob', false);
|
||||
setChecked('Wrapperiframe', true);
|
||||
try { saveSettingsDebounced(); } catch (e) {}
|
||||
try { saveSettingsDebounced(); } catch (e) { }
|
||||
});
|
||||
} catch (err) {}
|
||||
} catch (err) { }
|
||||
}
|
||||
|
||||
function setupDebugButtonInSettings() {
|
||||
@@ -555,7 +555,7 @@ function setupDebugButtonInSettings() {
|
||||
try {
|
||||
const mod = await import('./modules/debug-panel/debug-panel.js');
|
||||
if (mod?.toggleDebugPanel) await mod.toggleDebugPanel();
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
};
|
||||
btn.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); onActivate(); });
|
||||
btn.addEventListener('keydown', (e) => {
|
||||
@@ -563,7 +563,7 @@ function setupDebugButtonInSettings() {
|
||||
});
|
||||
|
||||
row.appendChild(btn);
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
function setupMenuTabs() {
|
||||
@@ -608,7 +608,7 @@ jQuery(async () => {
|
||||
|
||||
await setupSettings();
|
||||
|
||||
try { initControlAudio(); } catch (e) {}
|
||||
try { initControlAudio(); } catch (e) { }
|
||||
|
||||
if (isXiaobaixEnabled) {
|
||||
initRenderer();
|
||||
@@ -617,20 +617,25 @@ jQuery(async () => {
|
||||
try {
|
||||
if (isXiaobaixEnabled && settings.wrapperIframe && !document.getElementById('xb-callgen'))
|
||||
document.head.appendChild(Object.assign(document.createElement('script'), { id: 'xb-callgen', type: 'module', src: `${extensionFolderPath}/bridges/call-generate-service.js` }));
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
|
||||
try {
|
||||
if (isXiaobaixEnabled && !document.getElementById('xb-worldbook'))
|
||||
document.head.appendChild(Object.assign(document.createElement('script'), { id: 'xb-worldbook', type: 'module', src: `${extensionFolderPath}/bridges/worldbook-bridge.js` }));
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
|
||||
try {
|
||||
if (isXiaobaixEnabled && !document.getElementById('xb-contextbridge'))
|
||||
document.head.appendChild(Object.assign(document.createElement('script'), { id: 'xb-contextbridge', type: 'module', src: `${extensionFolderPath}/bridges/context-bridge.js` }));
|
||||
} catch (e) { }
|
||||
|
||||
eventSource.on(event_types.APP_READY, () => {
|
||||
setTimeout(performExtensionUpdateCheck, 2000);
|
||||
});
|
||||
|
||||
if (isXiaobaixEnabled) {
|
||||
try { initVarCommands(); } catch (e) {}
|
||||
try { initVareventEditor(); } catch (e) {}
|
||||
try { initVarCommands(); } catch (e) { }
|
||||
try { initVareventEditor(); } catch (e) { }
|
||||
|
||||
if (settings.tasks?.enabled) {
|
||||
try { await initTasks(); } catch (e) { console.error('[Tasks] Init failed:', e); }
|
||||
@@ -665,7 +670,7 @@ jQuery(async () => {
|
||||
setInterval(() => {
|
||||
if (isXiaobaixEnabled) processExistingMessages();
|
||||
}, 30000);
|
||||
} catch (err) {}
|
||||
} catch (err) { }
|
||||
});
|
||||
|
||||
export { executeSlashCommand };
|
||||
export { executeSlashCommand };
|
||||
Reference in New Issue
Block a user