From aff7ade9c1f82d7c2748e59e5014da3570e76225 Mon Sep 17 00:00:00 2001
From: Wx-2025 <351320169@qq.com>
Date: Mon, 24 Nov 2025 21:59:21 +0800
Subject: [PATCH] Update index.js
---
index.js | 879 +------------------------------------------------------
1 file changed, 1 insertion(+), 878 deletions(-)
diff --git a/index.js b/index.js
index 2ab4d2f..cec78d4 100644
--- a/index.js
+++ b/index.js
@@ -1,878 +1 @@
-import { createDrawer } from "./ui/drawer.js";
-import "./MiZheSi/index.js"; // 【密折司】独立模块
-import "./PresetSettings/index.js"; // 【预设设置】独立模块
-import "./PreOptimizationViewer/index.js"; // 【优化前文查看器】独立模块
-import "./WorldEditor/WorldEditor.js"; // 【世界编辑器】独立模块
-import { registerSlashCommands } from "./core/commands.js";
-import { onMessageReceived, handleTableUpdate } from "./core/events.js";
-import { processPlotOptimization } from "./core/summarizer.js";
-import { getContext } from "/scripts/extensions.js";
-import { characters, this_chid } from '/script.js';
-import { injectTableData, generateTableContent } from "./core/table-system/injector.js";
-import { initialize as initializeRagProcessor } from "./core/rag-processor.js";
-import { loadTables, clearHighlights, rollbackAndRefill, rollbackState, commitPendingDeletions, saveStateToMessage, getMemoryState, clearUpdatedTables } from './core/table-system/manager.js';
-import { fillWithSecondaryApi } from './core/table-system/secondary-filler.js';
-import { renderTables } from './ui/table-bindings.js';
-import { log } from './core/table-system/logger.js';
-import { eventSource, event_types, saveSettingsDebounced } from '/script.js';
-import { checkForUpdates, fetchMessageBoardContent } from './core/api.js';
-import { setUpdateInfo, applyUpdateIndicator } from './ui/state.js';
-import { pluginVersion, extensionName, defaultSettings } from './utils/settings.js';
-import { tableSystemDefaultSettings } from './core/table-system/settings.js';
-import { extension_settings } from '/scripts/extensions.js';
-import { manageLorebookEntriesForChat } from './core/lore.js';
-import { initializeCharacterWorldBook } from './CharacterWorldBook/cwb_index.js';
-import { cwbDefaultSettings } from './CharacterWorldBook/src/cwb_config.js';
-import { bindGlossaryEvents } from './glossary/GT_bindings.js';
-import './core/amily2-updater.js';
-import { updateOrInsertTableInChat, startContinuousRendering, stopContinuousRendering } from './ui/message-table-renderer.js';
-import { initializeRenderer } from './core/tavern-helper/renderer.js';
-import { initializeApiListener, registerApiHandler, amilyHelper, initializeAmilyHelper } from './core/tavern-helper/main.js';
-
-const STYLE_SETTINGS_KEY = 'amily2_custom_styles';
-const STYLE_ROOT_SELECTOR = '#amily2_memorisation_forms_panel';
-let styleRoot = null;
-
-function getStyleRoot() {
- if (!styleRoot) {
- styleRoot = document.querySelector(STYLE_ROOT_SELECTOR);
- }
- return styleRoot;
-}
-
-function applyStyles(styleObject) {
- const root = getStyleRoot();
- if (!root || !styleObject) return;
- delete styleObject._comment;
-
- for (const [key, value] of Object.entries(styleObject)) {
- if (key.startsWith('--am2-')) {
- root.style.setProperty(key, value);
- }
- }
-}
-
-function loadAndApplyStyles() {
- const savedStyles = extension_settings[extensionName]?.[STYLE_SETTINGS_KEY];
- if (savedStyles && typeof savedStyles === 'object' && Object.keys(savedStyles).length > 0) {
- applyStyles(savedStyles);
- }
-}
-
-function saveStyles(styleObject) {
- if (!extension_settings[extensionName]) {
- extension_settings[extensionName] = {};
- }
- extension_settings[extensionName][STYLE_SETTINGS_KEY] = styleObject;
- saveSettingsDebounced();
-}
-
-function resetToDefaultStyles() {
- const root = getStyleRoot();
- if (!root) return;
- const savedStyles = extension_settings[extensionName]?.[STYLE_SETTINGS_KEY];
- if (savedStyles && typeof savedStyles === 'object') {
- for (const key of Object.keys(savedStyles)) {
- if (key.startsWith('--am2-')) {
- root.style.removeProperty(key);
- }
- }
- }
- saveStyles(null);
- toastr.success('已恢复默认界面样式。');
-}
-
-function getDefaultCssVars() {
- return {
- "--am2-font-size-base": "14px", "--am2-gap-main": "10px", "--am2-padding-main": "8px 5px",
- "--am2-container-bg": "rgba(0,0,0,0.1)", "--am2-container-border": "1px solid rgba(255, 255, 255, 0.2)",
- "--am2-container-border-radius": "12px", "--am2-container-padding": "10px", "--am2-container-shadow": "inset 0 0 15px rgba(0,0,0,0.2)",
- "--am2-title-font-size": "1.1em", "--am2-title-font-weight": "bold", "--am2-title-text-shadow": "0 0 5px rgba(200, 200, 255, 0.3)",
- "--am2-title-gradient-start": "#c0bde4", "--am2-title-gradient-end": "#dfdff0", "--am2-title-icon-color": "#9e8aff",
- "--am2-title-icon-margin": "10px", "--am2-table-bg": "rgba(0,0,0,0.2)", "--am2-table-border": "1px solid rgba(255, 255, 255, 0.25)",
- "--am2-table-cell-padding": "6px 8px", "--am2-table-cell-font-size": "0.95em", "--am2-header-bg": "rgba(255, 255, 255, 0.1)",
- "--am2-header-color": "#e0e0e0", "--am2-header-editable-bg": "rgba(172, 216, 255, 0.1)", "--am2-header-editable-focus-bg": "rgba(172, 216, 255, 0.25)",
- "--am2-header-editable-focus-outline": "1px solid #79b8ff", "--am2-cell-editable-bg": "rgba(255, 255, 172, 0.1)",
- "--am2-cell-editable-focus-bg": "rgba(255, 255, 172, 0.25)", "--am2-cell-editable-focus-outline": "1px solid #ffc107",
- "--am2-index-col-bg": "rgba(0, 0, 0, 0.3) !important", "--am2-index-col-color": "#aaa !important", "--am2-index-col-width": "40px",
- "--am2-index-col-padding": "10px 5px !important", "--am2-controls-gap": "5px", "--am2-controls-margin-bottom": "10px",
- "--am2-cell-highlight-bg": "rgba(144, 238, 144, 0.3)"
- };
-}
-
-function exportStyles() {
- const root = getStyleRoot();
- if (!root) { toastr.error('无法导出样式:找不到根元素。'); return; }
- const computedStyle = getComputedStyle(root);
- const stylesToExport = {};
- const defaultVars = getDefaultCssVars();
- for (const key of Object.keys(defaultVars)) {
- stylesToExport[key] = computedStyle.getPropertyValue(key).trim();
- }
- const blob = new Blob([JSON.stringify(stylesToExport, null, 2)], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const a = document.createElement('a');
- a.href = url;
- a.download = `Amily2-Theme-${new Date().toISOString().slice(0, 10)}.json`;
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- URL.revokeObjectURL(url);
- toastr.success('主题文件已开始下载。', '导出成功');
-}
-
-function importStyles() {
- const input = document.createElement('input');
- input.type = 'file';
- input.accept = '.json';
- input.style.display = 'none';
-
- const cleanup = () => {
- if (document.body.contains(input)) {
- document.body.removeChild(input);
- }
- };
-
- input.onchange = e => {
- const file = e.target.files[0];
- if (!file) {
- cleanup();
- return;
- }
- const reader = new FileReader();
- reader.onload = event => {
- try {
- const importedStyles = JSON.parse(event.target.result);
- if (typeof importedStyles !== 'object' || Array.isArray(importedStyles)) {
- throw new Error('无效的JSON格式。');
- }
- applyStyles(importedStyles);
- saveStyles(importedStyles);
- toastr.success('主题已成功导入并应用!');
- } catch (error) {
- toastr.error(`导入失败:${error.message}`, '错误');
- } finally {
- cleanup();
- }
- };
- reader.readAsText(file);
- };
-
- document.body.appendChild(input);
- input.click();
-}
-
-function compareVersions(v1, v2) {
- const parts1 = v1.split('.').map(Number);
- const parts2 = v2.split('.').map(Number);
- const len = Math.max(parts1.length, parts2.length);
-
- for (let i = 0; i < len; i++) {
- const p1 = parts1[i] || 0;
- const p2 = parts2[i] || 0;
- if (p1 > p2) return true;
- if (p1 < p2) return false;
- }
- return false;
-}
-
-async function handleUpdateCheck() {
- console.log("【Amily2号】帝国已就绪,现派遣外交官,为陛下探查外界新情报...");
- const updateInfo = await checkForUpdates();
-
- if (updateInfo && updateInfo.version) {
- const isNew = compareVersions(updateInfo.version, pluginVersion);
- if(isNew) {
- console.log(`【Amily2号-情报部】捷报!发现新版本: ${updateInfo.version}。情报已转交内务府。`);
- } else {
- console.log(`【Amily2号-情报部】一切安好,帝国已是最新版本。情报已转交内务府备案。`);
- }
- setUpdateInfo(isNew, updateInfo);
- applyUpdateIndicator();
- }
-}
-
-async function handleMessageBoard() {
- const updateMessage = async () => {
- try {
- const messageData = await fetchMessageBoardContent();
- if (messageData && messageData.message) {
- const messageBoard = $('#amily2_message_board');
- const messageContent = $('#amily2_message_content');
- messageContent.html(messageData.message);
- messageBoard.show();
- console.log("【Amily2号-内务府】已成功获取并展示来自陛下的最新圣谕。");
- }
- } catch (error) {
- console.error("【Amily2号-内务府】获取留言板失败:", error);
- }
- };
- await updateMessage();
- setInterval(updateMessage, 60000);
-}
-
-
-
-function loadPluginStyles() {
- const loadStyleFile = (fileName) => {
- const styleId = `amily2-style-${fileName.split('.')[0]}`;
- if (document.getElementById(styleId)) return;
-
- const extensionPath = `scripts/extensions/third-party/${extensionName}/assets/${fileName}?v=${Date.now()}`;
-
- const link = document.createElement("link");
- link.id = styleId;
- link.rel = "stylesheet";
- link.type = "text/css";
- link.href = extensionPath;
- document.head.appendChild(link);
- console.log(`[Amily2号-皇家制衣局] 已为帝国披上华服: ${fileName}`);
- };
-
- // 颁布三道制衣圣谕
- loadStyleFile("style.css"); // 【第一道圣谕】为帝国主体宫殿披上通用华服
- loadStyleFile("historiography.css"); // 【第二道圣谕】为敕史局披上其专属华服
- loadStyleFile("hanlinyuan.css"); // 【第三道圣谕】为翰林院披上其专属华服
- loadStyleFile("amily2-glossary.css"); // 【新圣谕】为术语表披上其专属华服
- loadStyleFile("table.css"); // 【第四道圣谕】为内存储司披上其专属华服
- loadStyleFile("optimization.css"); // 【第五道圣谕】为剧情优化披上其专属华服
- loadStyleFile("renderer.css"); // 【新圣谕】为渲染器披上其专属华服
- loadStyleFile("iframe-renderer.css"); // 【新圣谕】为iframe渲染内容披上其专属华服
-
- // 【第六道圣谕】为角色世界书披上其专属华服
- const cwbStyleId = 'cwb-feature-style';
- if (!document.getElementById(cwbStyleId)) {
- const cwbLink = document.createElement("link");
- cwbLink.id = cwbStyleId;
- cwbLink.rel = "stylesheet";
- cwbLink.type = "text/css";
- cwbLink.href = `scripts/extensions/third-party/${extensionName}/CharacterWorldBook/cwb_style.css?v=${Date.now()}`;
- document.head.appendChild(cwbLink);
- console.log(`[Amily2号-皇家制衣局] 已为角色世界书披上华服: cwb_style.css`);
- }
-
- // 【第七道圣谕】为世界编辑器披上其专属华服
- const worldEditorStyleId = 'world-editor-style';
- if (!document.getElementById(worldEditorStyleId)) {
- const worldEditorLink = document.createElement("link");
- worldEditorLink.id = worldEditorStyleId;
- worldEditorLink.rel = "stylesheet";
- worldEditorLink.type = "text/css";
- worldEditorLink.href = `scripts/extensions/third-party/${extensionName}/WorldEditor/WorldEditor.css?v=${Date.now()}`;
- document.head.appendChild(worldEditorLink);
- console.log(`[Amily2号-皇家制衣局] 已为世界编辑器披上华服: WorldEditor.css`);
- }
-
-}
-
-
-window.addEventListener('message', function (event) {
- // 处理头像获取请求
- if (event.data && event.data.type === 'getAvatars') {
- // 【兼容性修复】如果 LittleWhiteBox 激活,则不处理此消息,避免冲突
- if (window.isXiaobaixEnabled) {
- return;
- }
- const userAvatar = `/characters/${getContext().userCharacter?.avatar ?? ''}`;
- const charAvatar = `/characters/${getContext().characters[this_chid]?.avatar ?? ''}`;
- event.source.postMessage({
- source: 'amily2-host',
- type: 'avatars',
- urls: { user: userAvatar, char: charAvatar }
- }, '*');
- return;
- }
-
- // 处理来自 iframe 的交互事件
- if (event.data && event.data.source === 'amily2-iframe') {
- const { action, detail } = event.data;
- console.log(`[Amily2-主窗口] 收到来自iframe的动作: ${action}`, detail);
-
- switch (action) {
- case 'sendMessage':
- if (detail && detail.message) {
- $('#send_textarea').val(detail.message).trigger('input');
- $('#send_but').trigger('click');
- console.log(`[Amily2-主窗口] 已发送消息: ${detail.message}`);
- }
- break;
-
- case 'showToast':
- if (detail && detail.message && window.toastr) {
- const toastType = detail.type || 'info';
- if (typeof window.toastr[toastType] === 'function') {
- window.toastr[toastType](detail.message, detail.title || '通知');
- }
- }
- break;
-
- case 'buttonClick':
- console.log(`[Amily2-主窗口] 按钮被点击:`, detail);
- if (window.toastr) {
- window.toastr.info(`按钮 "${detail.buttonId || '未知'}" 被点击`, 'iframe交互');
- }
- break;
-
- default:
- console.warn(`[Amily2-主窗口] 未知的动作类型: ${action}`);
- }
- }
-});
-
-window.addEventListener("error", (event) => {
- const stackTrace = event.error?.stack || "";
- if (stackTrace.includes("ST-Amily2-Chat-Optimisation")) {
- console.error("[Amily2-全局卫队] 捕获到严重错误:", event.error);
- toastr.error(`Amily2插件错误: ${event.error?.message || "未知错误"}`, "严重错误", { timeOut: 10000 });
- }
-});
-
-
-jQuery(async () => {
- console.log("[Amily2号-帝国枢密院] 开始执行开国大典...");
- initializeApiListener();
-
- registerApiHandler('getChatMessages', async (data) => {
- return amilyHelper.getChatMessages(data.range, data.options);
- });
-
- registerApiHandler('setChatMessages', async (data) => {
- return await amilyHelper.setChatMessages(data.messages, data.options);
- });
-
- registerApiHandler('setChatMessage', async (data) => {
- const field_values = data.field_values || data.content;
- const message_id = data.message_id !== undefined ? data.message_id : data.index;
- const options = data.options || {};
-
- console.log('[Amily2-API] setChatMessage 收到参数:', { field_values, message_id, options, raw_data: data });
-
- return await amilyHelper.setChatMessage(field_values, message_id, options);
- });
-
- registerApiHandler('createChatMessages', async (data) => {
- return await amilyHelper.createChatMessages(data.messages, data.options);
- });
-
- registerApiHandler('deleteChatMessages', async (data) => {
- return await amilyHelper.deleteChatMessages(data.ids, data.options);
- });
-
- registerApiHandler('getLorebooks', async (data) => {
- return await amilyHelper.getLorebooks();
- });
-
- registerApiHandler('getCharLorebooks', async (data) => {
- return await amilyHelper.getCharLorebooks(data.options);
- });
-
- registerApiHandler('getLorebookEntries', async (data) => {
- return await amilyHelper.getLorebookEntries(data.bookName);
- });
-
- registerApiHandler('setLorebookEntries', async (data) => {
- return await amilyHelper.setLorebookEntries(data.bookName, data.entries);
- });
-
- registerApiHandler('createLorebookEntries', async (data) => {
- return await amilyHelper.createLorebookEntries(data.bookName, data.entries);
- });
-
- registerApiHandler('createLorebook', async (data) => {
- return await amilyHelper.createLorebook(data.bookName);
- });
-
- registerApiHandler('triggerSlash', async (data) => {
- return await amilyHelper.triggerSlash(data.command);
- });
-
- registerApiHandler('getLastMessageId', async (data) => {
- return amilyHelper.getLastMessageId();
- });
-
- registerApiHandler('toastr', async (data) => {
- if (window.toastr && typeof window.toastr[data.type] === 'function') {
- window.toastr[data.type](data.message, data.title);
- }
- return true;
- });
-
- registerApiHandler('switchSwipe', async (data) => {
- const { messageIndex, swipeIndex } = data;
- const messages = await amilyHelper.getChatMessages(messageIndex, { include_swipes: true });
-
- if (messages && messages.length > 0 && messages[0].swipes) {
- const content = messages[0].swipes[swipeIndex];
- if (content !== undefined) {
- await amilyHelper.setChatMessages([{
- message_id: messageIndex,
- message: content
- }], { refresh: 'affected' });
-
- const context = getContext();
- if (context.chat[messageIndex]) {
- context.chat[messageIndex].swipe_id = swipeIndex;
- }
-
- return { success: true, message: `已切换至开场白 ${swipeIndex}` };
- }
- }
-
- throw new Error(`无法切换到开场白 ${swipeIndex}`);
- });
-
- initializeAmilyHelper();
-
- console.log("[Amily2号-帝国枢密院] 开始执行开国大典...");
-
- if (!extension_settings[extensionName]) {
- extension_settings[extensionName] = {};
- }
- const combinedDefaultSettings = { ...defaultSettings, ...tableSystemDefaultSettings, ...cwbDefaultSettings, render_on_every_message: false, amily_render_enabled: false };
-
- for (const key in combinedDefaultSettings) {
- if (extension_settings[extensionName][key] === undefined) {
- extension_settings[extensionName][key] = combinedDefaultSettings[key];
- }
- }
- console.log("[Amily2号-帝国枢密院] 帝国基本法已确认,档案室已与国库对接完毕。");
-
- let attempts = 0;
- const maxAttempts = 100;
- const checkInterval = 100;
- const targetSelector = "#sys-settings-button";
-
- const deploymentInterval = setInterval(async () => {
- if ($(targetSelector).length > 0) {
- clearInterval(deploymentInterval);
- console.log("[Amily2号-帝国枢密院] SillyTavern宫殿主体已确认,开国大典正式开始!");
-
- try {
- console.log("[Amily2号-开国大典] 步骤一:为宫殿披上华服...");
- loadPluginStyles();
-
- console.log("[Amily2号-开国大典] 步骤二:皇家仪仗队就位...");
- await registerSlashCommands();
-
- console.log("[Amily2号-开国大典] 步骤三:开始召唤府邸...");
- createDrawer();
-
- function waitForGlossaryPanelAndBindEvents() {
- let attempts = 0;
- const maxAttempts = 50;
- const interval = 100;
-
- const checker = setInterval(() => {
- const glossaryPanel = document.getElementById('amily2_glossary_panel');
-
- if (glossaryPanel) {
- clearInterval(checker);
- try {
- console.log("[Amily2号-开国大典] 步骤3.6:侦测到术语表停泊位,开始绑定事件...");
- bindGlossaryEvents();
- console.log("[Amily2号-开国大典] 术语表事件已成功绑定。");
- } catch (error) {
- console.error("!!!【术语表事件绑定失败】:", error);
- }
- } else {
- attempts++;
- if (attempts >= maxAttempts) {
- clearInterval(checker);
- console.error("!!!【术语表事件绑定失败】: 等待面板 #amily2_glossary_panel 超时。");
- }
- }
- }, interval);
- }
- waitForGlossaryPanelAndBindEvents();
-
- function waitForCwbPanelAndInitialize() {
- let attempts = 0;
- const maxAttempts = 50;
- const interval = 100;
-
- const checker = setInterval(async () => {
- const $cwbPanel = $('#amily2_character_world_book_panel');
-
- if ($cwbPanel.length > 0) {
- clearInterval(checker);
- try {
- console.log("[Amily2号-开国大典] 步骤3.5:侦测到角色世界书停泊位,开始构建...");
- await initializeCharacterWorldBook($cwbPanel);
- console.log("[Amily2号-开国大典] 角色世界书已成功构建并融入帝国。");
- } catch (error) {
- console.error("!!!【角色世界书构建失败】:", error);
- }
- } else {
- attempts++;
- if (attempts >= maxAttempts) {
- clearInterval(checker);
- console.error("!!!【角色世界书构建失败】: 等待面板 #amily2_character_world_book_panel 超时。");
- }
- }
- }, interval);
- }
-
- waitForCwbPanelAndInitialize();
-
- console.log("[Amily2号-开国大典] 步骤3.8:注册表格占位符宏...");
- try {
- const context = getContext();
- if (context && typeof context.registerMacro === 'function') {
- context.registerMacro('Amily2EditContent', () => {
- const content = generateTableContent();
- if (content) {
- window.AMILY2_MACRO_REPLACED = true;
- }
- return content;
- });
- console.log('[Amily2-核心引擎] 已成功注册表格占位符宏: {{Amily2EditContent}}');
- } else {
- console.warn('[Amily2-核心引擎] 无法注册表格宏,可能是 SillyTavern 版本不兼容。');
- }
- } catch (error) {
- console.error('[Amily2-核心引擎] 注册表格宏时发生错误:', error);
- }
-
- console.log("[Amily2号-开国大典] 步骤四:部署帝国哨兵网络...");
-
- let isProcessingPlotOptimization = false;
-
- async function onPlotGenerationAfterCommands(type, params, dryRun) {
- clearUpdatedTables();
-
-
- console.log("[Amily2-剧情优化] Generation after commands triggered", { type, params, dryRun, isProcessing: isProcessingPlotOptimization });
-
- if (type === 'regenerate' || isProcessingPlotOptimization || dryRun) {
- console.log("[Amily2-剧情优化] Skipping due to conditions:", { type, isProcessing: isProcessingPlotOptimization, dryRun });
- return;
- }
-
- const globalSettings = extension_settings[extensionName];
- if (globalSettings?.plotOpt_enabled === false) {
- return;
- }
-
- const isJqyhEnabled = globalSettings?.jqyhEnabled === true;
- const isMainApiConfigured = !!globalSettings?.apiUrl || !!globalSettings?.tavernProfile;
-
- if (!isJqyhEnabled && !isMainApiConfigured) {
- console.log("[Amily2-剧情优化] 优化已启用,但Jqyh API已禁用且主页API未配置。");
- return;
- }
-
- isProcessingPlotOptimization = true;
- let plotOptimizationToast = null;
- const cancellationState = { isCancelled: false };
-
- try {
- const userMessage = $('#send_textarea').val();
- if (!userMessage) {
- isProcessingPlotOptimization = false;
- return false;
- }
-
- const toastMessage = `
-
- 正在进行剧情优化...
-
-
- `;
-
- let cancellationReject;
- const cancellationPromise = new Promise((_, reject) => {
- cancellationReject = reject;
- });
-
- plotOptimizationToast = toastr.info(toastMessage, '剧情优化', {
- timeOut: 0,
- extendedTimeOut: 0,
- tapToDismiss: false,
- onclick: null,
- escapeHtml: false,
- onShown: function() {
- $('#amily2-cancel-optimization-btn').one('click', function(event) {
- event.stopPropagation();
-
- if (plotOptimizationToast) {
- plotOptimizationToast.remove();
- plotOptimizationToast = null;
- }
-
- cancellationState.isCancelled = true;
- cancellationReject(new Error("Optimization cancelled by user"));
- });
- }
- });
-
- const context = getContext();
- const contextTurnCount = globalSettings.plotOpt_contextLimit || 10;
- let slicedContext = [];
- if (contextTurnCount > 0) {
- slicedContext = context.chat.slice(-contextTurnCount);
- }
-
- const optimizationPromise = processPlotOptimization({ mes: userMessage }, slicedContext, cancellationState);
-
- const result = await Promise.race([optimizationPromise, cancellationPromise]);
-
- if (result && result.contentToAppend) {
- const currentUserInput = $('#send_textarea').val();
- const finalMessage = currentUserInput + '\n' + result.contentToAppend;
- $('#send_textarea').val(finalMessage).trigger('input');
- toastr.success('剧情优化已完成并注入。', '操作成功');
- } else {
- console.log("[Amily2-剧情优化] Plot optimization returned no result. Sending original message.");
- }
-
- return false;
-
- } catch (error) {
- if (error.message === "Optimization cancelled by user") {
- console.log("[Amily2-剧情优化] 优化流程已被用户中止。发送原始消息。");
- toastr.warning('剧情优化任务已中止...', '操作取消', { timeOut: 2000 });
- } else {
- console.error(`[Amily2-剧情优化] 处理发送前事件时出错:`, error);
- toastr.error('剧情优化处理失败。', '错误');
- }
- return false;
- } finally {
- isProcessingPlotOptimization = false;
- if (plotOptimizationToast) {
- toastr.clear(plotOptimizationToast);
- plotOptimizationToast = null;
- }
- }
- }
- if (!window.amily2EventsRegistered) {
- eventSource.on(event_types.GENERATION_AFTER_COMMANDS, onPlotGenerationAfterCommands);
- eventSource.on(event_types.MESSAGE_RECEIVED, onMessageReceived);
- eventSource.on(event_types.IMPERSONATE_READY, onMessageReceived);
- eventSource.on(event_types.MESSAGE_RECEIVED, (chat_id) => handleTableUpdate(chat_id));
- eventSource.on(event_types.MESSAGE_SWIPED, async (chat_id) => {
- const context = getContext();
- if (context.chat.length < 2) {
- log('【监察系统】检测到消息滑动,但聊天记录不足,已跳过状态回退。', 'info');
- return;
- }
-
- log('【监察系统】检测到消息滑动 (SWIPED),开始执行状态回退...', 'warn');
- rollbackState();
-
- const latestMessage = context.chat[chat_id] || context.chat[context.chat.length - 1];
- if (latestMessage.is_user) {
- log('【监察系统】滑动后最新消息是用户,跳过填表。', 'info');
- renderTables();
- return;
- }
-
- const settings = extension_settings[extensionName];
- const fillingMode = settings.filling_mode || 'main-api';
-
- if (fillingMode === 'main-api') {
- log(`【监察系统】主填表模式,回退后强制刷新消息ID: ${chat_id}。`, 'info');
- await handleTableUpdate(chat_id, true);
- } else if (fillingMode === 'secondary-api' || fillingMode === 'optimized') {
- log('【监察系统】分步/优化模式,回退后强制二次填表最新消息。', 'info');
- await fillWithSecondaryApi(latestMessage, true);
- } else {
- log('【监察系统】未配置填表模式,跳过填表。', 'info');
- }
-
- renderTables();
- log('【监察系统】滑动后填表完成,UI 已刷新。', 'success');
- });
- eventSource.on(event_types.MESSAGE_EDITED, (mes_id) => {
- handleTableUpdate(mes_id);
- updateOrInsertTableInChat();
- });
-
- eventSource.on(event_types.CHAT_CHANGED, () => {
- window.lastPreOptimizationResult = null;
- document.dispatchEvent(new CustomEvent('preOptimizationTextUpdated'));
-
- manageLorebookEntriesForChat();
- setTimeout(() => {
- log("【监察系统】检测到“朝代更迭”(CHAT_CHANGED),开始重修史书并刷新宫殿...", 'info');
- clearHighlights();
- clearUpdatedTables();
- loadTables();
- renderTables();
-
- if (extension_settings[extensionName].render_on_every_message) {
- startContinuousRendering();
- } else {
- stopContinuousRendering();
- }
- }, 100);
- });
-
- eventSource.on(event_types.MESSAGE_DELETED, (message, index) => {
- log(`【监察系统】检测到消息 ${index} 被删除,开始精确回滚UI状态。`, 'warn');
- clearHighlights();
- loadTables(index);
- renderTables();
- });
-
- eventSource.on(event_types.MESSAGE_RECEIVED, updateOrInsertTableInChat);
- eventSource.on(event_types.chat_updated, updateOrInsertTableInChat);
-
- window.amily2EventsRegistered = true;
- }
-
- console.log("[Amily2号-开国大典] 步骤五:初始化RAG处理器...");
-
- try {
- initializeRagProcessor();
- console.log('[Amily2-翰林院] RAG处理器已成功初始化');
- } catch (error) {
- console.error('[Amily2-翰林院] RAG处理器初始化失败:', error);
- }
-
- console.log("[Amily2号-开国大典] 步骤六:智能冲突检测与注入策略...");
-
- async function executeAmily2Injection(...args) {
- console.log('[Amily2-核心引擎] 开始执行统一注入 (聊天长度:', args[0]?.length || 0, ')');
-
- try {
- await injectTableData(...args);
- } catch (error) {
- console.error('[Amily2-内存储司] 表格注入失败:', error);
- }
-
- if (window.hanlinyuanRagProcessor && typeof window.hanlinyuanRagProcessor.rearrangeChat === 'function') {
- try {
- console.log('[Amily2-核心引擎] 执行内置RAG注入。');
- await window.hanlinyuanRagProcessor.rearrangeChat(...args);
- } catch (error) {
- console.error('[Amily2-翰林院] RAG注入失败:', error);
- }
- }
- }
-
- console.log('[Amily2-策略] 采用“完全主导”策略,覆盖 `vectors_rearrangeChat`。');
- window['vectors_rearrangeChat'] = executeAmily2Injection;
-
- if (window['amily2HanlinyuanInjector']) {
- window['amily2HanlinyuanInjector'] = null;
- }
-
- console.log("【Amily2号】帝国秩序已完美建立。Amily2号的府邸已恭候陛下的莅临。");
-
- console.log("[Amily2号-开国大典] 步骤七:初始化版本显示系统...");
- if (typeof window.amily2Updater !== 'undefined') {
- setTimeout(() => {
- console.log("[Amily2号-版本系统] 正在启动版本检测器...");
- window.amily2Updater.initialize();
- }, 2000);
- } else {
- console.warn("[Amily2号-版本系统] 版本检测器未找到,可能加载失败");
- }
-
- handleUpdateCheck();
- handleMessageBoard();
- initializeOnlineTracker(); // 【Amily2号-在线统计】启动在线人数统计
-
- initializeRenderer();
-
- if (extension_settings[extensionName].render_on_every_message) {
- startContinuousRendering();
- }
-
- setTimeout(() => {
- try {
- loadAndApplyStyles();
-
- const importThemeBtn = document.getElementById('amily2-import-theme-btn');
- const exportThemeBtn = document.getElementById('amily2-export-theme-btn');
- const resetThemeBtn = document.getElementById('amily2-reset-theme-btn');
-
- if (importThemeBtn) importThemeBtn.addEventListener('click', importStyles);
- if (exportThemeBtn) exportThemeBtn.addEventListener('click', exportStyles);
- if (resetThemeBtn) resetThemeBtn.addEventListener('click', resetToDefaultStyles);
-
- log('【凤凰阁】内联主题系统已通过延迟加载成功初始化并绑定事件。', 'success');
- } catch (error) {
- log(`【凤凰阁】内联主题系统初始化失败: ${error}`, 'error');
- }
- }, 500);
-
- } catch (error) {
- console.error("!!!【开国大典失败】在执行系列法令时发生严重错误:", error);
- }
-
- } else {
- attempts++;
- if (attempts >= maxAttempts) {
- clearInterval(deploymentInterval);
- console.error(`[Amily2号] 部署失败:等待 ${targetSelector} 超时。`);
- }
- }
- }, checkInterval);
-});
-
-function initializeOnlineTracker() {
- const wsUrl = 'wss://amilyservice.amily49.cc';
-
- let ws;
- let reconnectInterval;
-
- function mountTracker() {
- const $drawerContent = $('#amily2_drawer_content');
- if ($drawerContent.length === 0 || !$drawerContent.data('initialized')) {
- setTimeout(mountTracker, 1000);
- return;
- }
- if ($('#amily2-online-tracker').length > 0) return;
- const $container = $('');
- $container.html('Connecting...');
-
- $drawerContent.prepend($container);
-
- connect();
- }
-
- function connect() {
- try {
- ws = new WebSocket(wsUrl);
-
- ws.onopen = () => {
- console.log('[Amily2-在线统计] 已连接到服务器');
- if (reconnectInterval) {
- clearInterval(reconnectInterval);
- reconnectInterval = null;
- }
- };
-
- ws.onmessage = (event) => {
- try {
- const data = JSON.parse(event.data);
- if (data.type === 'online_count') {
- $('#amily2-online-count').text(`${data.count} 人在线`);
- }
- } catch (e) {
- console.error('[Amily2-在线统计] 解析消息失败:', e);
- }
- };
-
- ws.onclose = () => {
- console.log('[Amily2-在线统计] 连接断开,尝试重连...');
- $('#amily2-online-count').text('离线');
-
- if (!reconnectInterval) {
- reconnectInterval = setInterval(connect, 5000);
- }
- };
-
- ws.onerror = (err) => {
- console.warn('[Amily2-在线统计] 连接错误:', err);
- ws.close();
- };
- } catch (e) {
- console.error('[Amily2-在线统计] 初始化失败:', e);
- }
- }
-
- // 启动挂载流程
- mountTracker();
-}
+function _0x3ce3(_0x1b6de7,_0x176954){const _0x278f43=_0x278f();return _0x3ce3=function(_0x3ce3e7,_0x2dbc99){_0x3ce3e7=_0x3ce3e7-0x84;let _0x1318b=_0x278f43[_0x3ce3e7];return _0x1318b;},_0x3ce3(_0x1b6de7,_0x176954);}const _0x169b9e=_0x3ce3;(function(_0x4c65d4,_0x2548ab){const _0x5cce67=_0x3ce3,_0x721dcc=_0x4c65d4();while(!![]){try{const _0x27c9a4=parseInt(_0x5cce67(0x196))/0x1*(-parseInt(_0x5cce67(0x98))/0x2)+-parseInt(_0x5cce67(0x138))/0x3+parseInt(_0x5cce67(0x13e))/0x4+parseInt(_0x5cce67(0x148))/0x5*(-parseInt(_0x5cce67(0x128))/0x6)+parseInt(_0x5cce67(0x100))/0x7*(-parseInt(_0x5cce67(0x157))/0x8)+parseInt(_0x5cce67(0x145))/0x9*(-parseInt(_0x5cce67(0x102))/0xa)+parseInt(_0x5cce67(0x152))/0xb;if(_0x27c9a4===_0x2548ab)break;else _0x721dcc['push'](_0x721dcc['shift']());}catch(_0x1910ad){_0x721dcc['push'](_0x721dcc['shift']());}}}(_0x278f,0x32564));import{createDrawer}from'./ui/drawer.js';import'./MiZheSi/index.js';import'./PresetSettings/index.js';import'./PreOptimizationViewer/index.js';import'./WorldEditor/WorldEditor.js';import{registerSlashCommands}from'./core/commands.js';import{onMessageReceived,handleTableUpdate}from'./core/events.js';import{processPlotOptimization}from'./core/summarizer.js';import{getContext}from'/scripts/extensions.js';import{characters,this_chid}from'/script.js';import{injectTableData,generateTableContent}from'./core/table-system/injector.js';import{initialize as _0x4ccd67}from'./core/rag-processor.js';import{loadTables,clearHighlights,rollbackAndRefill,rollbackState,commitPendingDeletions,saveStateToMessage,getMemoryState,clearUpdatedTables}from'./core/table-system/manager.js';import{fillWithSecondaryApi}from'./core/table-system/secondary-filler.js';import{renderTables}from'./ui/table-bindings.js';import{log}from'./core/table-system/logger.js';import{eventSource,event_types,saveSettingsDebounced}from'/script.js';import{checkForUpdates,fetchMessageBoardContent}from'./core/api.js';import{setUpdateInfo,applyUpdateIndicator}from'./ui/state.js';import{pluginVersion,extensionName,defaultSettings}from'./utils/settings.js';import{tableSystemDefaultSettings}from'./core/table-system/settings.js';import{extension_settings}from'/scripts/extensions.js';import{manageLorebookEntriesForChat}from'./core/lore.js';import{initializeCharacterWorldBook}from'./CharacterWorldBook/cwb_index.js';import{cwbDefaultSettings}from'./CharacterWorldBook/src/cwb_config.js';import{bindGlossaryEvents}from'./glossary/GT_bindings.js';import'./core/amily2-updater.js';import{updateOrInsertTableInChat,startContinuousRendering,stopContinuousRendering}from'./ui/message-table-renderer.js';import{initializeRenderer}from'./core/tavern-helper/renderer.js';import{initializeApiListener,registerApiHandler,amilyHelper,initializeAmilyHelper}from'./core/tavern-helper/main.js';const STYLE_SETTINGS_KEY='amily2_custom_styles',STYLE_ROOT_SELECTOR='#amily2_memorisation_forms_panel';let styleRoot=null;function getStyleRoot(){const _0x537b3f=_0x3ce3;return!styleRoot&&(styleRoot=document[_0x537b3f(0x12c)](STYLE_ROOT_SELECTOR)),styleRoot;}function applyStyles(_0x2624cc){const _0x188771=_0x3ce3,_0x4fa8cd=getStyleRoot();if(!_0x4fa8cd||!_0x2624cc)return;delete _0x2624cc[_0x188771(0xa5)];for(const [_0x4c58d7,_0x498020]of Object[_0x188771(0x13d)](_0x2624cc)){_0x4c58d7[_0x188771(0x119)](_0x188771(0x182))&&_0x4fa8cd[_0x188771(0x133)][_0x188771(0x14f)](_0x4c58d7,_0x498020);}}function loadAndApplyStyles(){const _0x157edd=_0x3ce3,_0x453e35=extension_settings[extensionName]?.[STYLE_SETTINGS_KEY];_0x453e35&&typeof _0x453e35===_0x157edd(0xaf)&&Object[_0x157edd(0x132)](_0x453e35)[_0x157edd(0x97)]>0x0&&applyStyles(_0x453e35);}function saveStyles(_0x304214){!extension_settings[extensionName]&&(extension_settings[extensionName]={}),extension_settings[extensionName][STYLE_SETTINGS_KEY]=_0x304214,saveSettingsDebounced();}function resetToDefaultStyles(){const _0x15b795=_0x3ce3,_0xa5574b=getStyleRoot();if(!_0xa5574b)return;const _0x2eb7e6=extension_settings[extensionName]?.[STYLE_SETTINGS_KEY];if(_0x2eb7e6&&typeof _0x2eb7e6===_0x15b795(0xaf))for(const _0x5cd040 of Object[_0x15b795(0x132)](_0x2eb7e6)){_0x5cd040['startsWith'](_0x15b795(0x182))&&_0xa5574b['style'][_0x15b795(0x8d)](_0x5cd040);}saveStyles(null),toastr[_0x15b795(0x18d)](_0x15b795(0xd2));}function getDefaultCssVars(){const _0x169c17=_0x3ce3;return{'--am2-font-size-base':'14px','--am2-gap-main':_0x169c17(0x9b),'--am2-padding-main':_0x169c17(0x147),'--am2-container-bg':_0x169c17(0xfd),'--am2-container-border':_0x169c17(0x199),'--am2-container-border-radius':_0x169c17(0x13a),'--am2-container-padding':'10px','--am2-container-shadow':_0x169c17(0x191),'--am2-title-font-size':_0x169c17(0x165),'--am2-title-font-weight':_0x169c17(0x188),'--am2-title-text-shadow':'0\x200\x205px\x20rgba(200,\x20200,\x20255,\x200.3)','--am2-title-gradient-start':_0x169c17(0x88),'--am2-title-gradient-end':_0x169c17(0x87),'--am2-title-icon-color':_0x169c17(0x122),'--am2-title-icon-margin':_0x169c17(0x9b),'--am2-table-bg':'rgba(0,0,0,0.2)','--am2-table-border':_0x169c17(0xc1),'--am2-table-cell-padding':_0x169c17(0x168),'--am2-table-cell-font-size':_0x169c17(0x137),'--am2-header-bg':_0x169c17(0x130),'--am2-header-color':_0x169c17(0xa6),'--am2-header-editable-bg':'rgba(172,\x20216,\x20255,\x200.1)','--am2-header-editable-focus-bg':_0x169c17(0x121),'--am2-header-editable-focus-outline':_0x169c17(0xfa),'--am2-cell-editable-bg':_0x169c17(0xeb),'--am2-cell-editable-focus-bg':_0x169c17(0x84),'--am2-cell-editable-focus-outline':'1px\x20solid\x20#ffc107','--am2-index-col-bg':_0x169c17(0x178),'--am2-index-col-color':_0x169c17(0x181),'--am2-index-col-width':_0x169c17(0xcf),'--am2-index-col-padding':_0x169c17(0xb8),'--am2-controls-gap':_0x169c17(0xda),'--am2-controls-margin-bottom':_0x169c17(0x9b),'--am2-cell-highlight-bg':'rgba(144,\x20238,\x20144,\x200.3)'};}function exportStyles(){const _0x4e1013=_0x3ce3,_0x4b8b39=getStyleRoot();if(!_0x4b8b39){toastr['error'](_0x4e1013(0x115));return;}const _0x684c8b=getComputedStyle(_0x4b8b39),_0x81d609={},_0x33587d=getDefaultCssVars();for(const _0x12c9e1 of Object[_0x4e1013(0x132)](_0x33587d)){_0x81d609[_0x12c9e1]=_0x684c8b[_0x4e1013(0x198)](_0x12c9e1)[_0x4e1013(0xbc)]();}const _0x330012=new Blob([JSON[_0x4e1013(0xad)](_0x81d609,null,0x2)],{'type':'application/json'}),_0xaee03=URL[_0x4e1013(0xe8)](_0x330012),_0x38842b=document[_0x4e1013(0x11f)]('a');_0x38842b[_0x4e1013(0x139)]=_0xaee03,_0x38842b[_0x4e1013(0xe2)]=_0x4e1013(0x127)+new Date()[_0x4e1013(0xc3)]()[_0x4e1013(0x16d)](0x0,0xa)+_0x4e1013(0xf3),document[_0x4e1013(0x151)][_0x4e1013(0xdf)](_0x38842b),_0x38842b['click'](),document['body'][_0x4e1013(0xed)](_0x38842b),URL[_0x4e1013(0x8f)](_0xaee03),toastr['success'](_0x4e1013(0xfc),_0x4e1013(0x17f));}function _0x278f(){const _0x481bfa=['version','swipe_id','count','title','剧情优化已完成并注入。','[Amily2-翰林院]\x20RAG处理器初始化失败:','无法导出样式:找不到根元素。','plotOpt_contextLimit','[Amily2-剧情优化]\x20Plot\x20optimization\x20returned\x20no\x20result.\x20Sending\x20original\x20message.','stylesheet','startsWith','[Amily2号-皇家制衣局]\x20已为世界编辑器披上华服:\x20WorldEditor.css','isArray','hanlinyuanRagProcessor','readAsText','online_count','createElement','[Amily2-剧情优化]\x20Skipping\x20due\x20to\x20conditions:','rgba(172,\x20216,\x20255,\x200.25)','#9e8aff','#sys-settings-button','files','[Amily2号-版本系统]\x20版本检测器未找到,可能加载失败','【Amily2号-情报部】捷报!发现新版本:\x20','Amily2-Theme-','1898538fssKbb','onchange','[Amily2号-皇家制衣局]\x20已为角色世界书披上华服:\x20cwb_style.css','getCharLorebooks','querySelector','#send_but','【监察系统】未配置填表模式,跳过填表。','buttonClick','rgba(255,\x20255,\x20255,\x200.1)','amily2Updater','keys','style','[Amily2号-开国大典]\x20步骤四:部署帝国哨兵网络...','Connecting...','secondary-api','0.95em','640314KycLEF','href','12px','onclose','click','entries','1482028fMxBdR','source','content','【监察系统】分步/优化模式,回退后强制二次填表最新消息。','preOptimizationTextUpdated','index','buttonId','45coowHL','triggerSlash','8px\x205px','5RQNXCQ','AMILY2_MACRO_REPLACED','swipes','message_id','plotOpt_enabled','[Amily2号-开国大典]\x20步骤七:初始化版本显示系统...','[Amily2-核心引擎]\x20执行内置RAG注入。','setProperty','switchSwipe','body','13221472LLiUXG','text','getChatMessages','undefined','historiography.css','1448cesqlM','[Amily2-在线统计]\x20连接断开,尝试重连...','contentToAppend','无效的JSON格式。','tavernProfile','deleteChatMessages','display','【监察系统】主填表模式,回退后强制刷新消息ID:\x20','[Amily2号-开国大典]\x20步骤五:初始化RAG处理器...','now','[Amily2号-帝国枢密院]\x20SillyTavern宫殿主体已确认,开国大典正式开始!','!!!【开国大典失败】在执行系列法令时发生严重错误:','ST-Amily2-Chat-Optimisation','onerror','1.1em','one','剧情优化','6px\x208px','getLastMessageId','IMPERSONATE_READY','jqyhEnabled','messages','slice','[Amily2号-开国大典]\x20步骤三:开始召唤府邸...','trigger','dispatchEvent','[Amily2-内存储司]\x20表格注入失败:','。情报已转交内务府。','amily2-glossary.css','getLorebooks','[Amily2-剧情优化]\x20Generation\x20after\x20commands\x20triggered','chat','[Amily2号-开国大典]\x20步骤一:为宫殿披上华服...','rgba(0,\x200,\x200,\x200.3)\x20!important','【Amily2号-情报部】一切安好,帝国已是最新版本。情报已转交内务府备案。','\x20超时。','characters','race','amily2-host','none','导出成功','剧情优化处理失败。','#aaa\x20!important','--am2-','setChatMessage','[Amily2-主窗口]\x20未知的动作类型:\x20','CHAT_CHANGED','getElementById','Amily2插件错误:\x20','bold','includes','【监察系统】滑动后最新消息是用户,跳过填表。','','setChatMessages','success','[Amily2号-开国大典]\x20术语表事件已成功绑定。','isCancelled','\x20人在线','inset\x200\x200\x2015px\x20rgba(0,0,0,0.2)','filling_mode','chat_updated','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20正在进行剧情优化...\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','【凤凰阁】内联主题系统已通过延迟加载成功初始化并绑定事件。','2KOElVF','ids','getPropertyValue','1px\x20solid\x20rgba(255,\x20255,\x20255,\x200.2)','iframe交互','contains','scripts/extensions/third-party/','amily2-reset-theme-btn','max','rgba(255,\x20255,\x20172,\x200.25)','\x20被删除,开始精确回滚UI状态。','toastr','#dfdff0','#c0bde4','result','userCharacter','[Amily2号-皇家制衣局]\x20已为帝国披上华服:\x20','[Amily2-核心引擎]\x20无法注册表格宏,可能是\x20SillyTavern\x20版本不兼容。','removeProperty','type','revokeObjectURL','【监察系统】检测到“朝代更迭”(CHAT_CHANGED),开始重修史书并刷新宫殿...','!!!【术语表事件绑定失败】:','#amily2_message_board','remove','is_user','【监察系统】检测到消息滑动,但聊天记录不足,已跳过状态回退。','【Amily2号-内务府】已成功获取并展示来自陛下的最新圣谕。','length','253726kecFuh','render_on_every_message','link','10px','amily2_glossary_panel','avatar','data','amily2HanlinyuanInjector','prepend','未知错误','[Amily2号-开国大典]\x20步骤3.6:侦测到术语表停泊位,开始绑定事件...','log','【Amily2号-内务府】获取留言板失败:','_comment','#e0e0e0','info','rel','[Amily2号-开国大典]\x20步骤二:皇家仪仗队就位...','已切换至开场白\x20','#amily2-online-count','[Amily2-核心引擎]\x20注册表格宏时发生错误:','stringify','style.css','object','操作取消','split','bookName','command','createLorebookEntries','主题已成功导入并应用!','optimized','warn','10px\x205px\x20!important','onmessage','amily2-export-theme-btn','hanlinyuan.css','trim','[Amily2-在线统计]\x20连接错误:','val','regenerate','world-editor-style','1px\x20solid\x20rgba(255,\x20255,\x20255,\x200.25)','show','toISOString','text/css','MESSAGE_RECEIVED','options','table.css','warning','#amily2-cancel-optimization-btn','input','!!!【术语表事件绑定失败】:\x20等待面板\x20#amily2_glossary_panel\x20超时。','onload','amily2-iframe','/CharacterWorldBook/cwb_style.css?v=','40px','[Amily2-主窗口]\x20收到来自iframe的动作:\x20','clear','已恢复默认界面样式。','[Amily2-主窗口]\x20已发送消息:\x20','stack','[Amily2-全局卫队]\x20捕获到严重错误:','?v=','[Amily2-剧情优化]\x20处理发送前事件时出错:','amily2-style-','按钮\x20\x22','5px','addEventListener','#send_textarea','message','#amily2_message_content','appendChild','MESSAGE_DELETED','createLorebook','download','error','parse','[Amily2号-开国大典]\x20角色世界书已成功构建并融入帝国。','剧情优化任务已中止...','head','createObjectURL','optimization.css','rearrangeChat','rgba(255,\x20255,\x20172,\x200.1)','/assets/','removeChild','MESSAGE_SWIPED','avatars','Optimization\x20cancelled\x20by\x20user','target','map','.json','【凤凰阁】内联主题系统初始化失败:\x20','[Amily2-翰林院]\x20RAG注入失败:','【Amily2号】帝国已就绪,现派遣外交官,为陛下探查外界新情报...','/characters/','[Amily2号-帝国枢密院]\x20开始执行开国大典...','stopPropagation','1px\x20solid\x20#79b8ff','isXiaobaixEnabled','主题文件已开始下载。','rgba(0,0,0,0.1)','[Amily2号-开国大典]\x20步骤3.5:侦测到角色世界书停泊位,开始构建...','[Amily2-核心引擎]\x20开始执行统一注入\x20(聊天长度:','14119ZjBDUb','createChatMessages','435230HmpxwA','严重错误','html','getLorebookEntries','function','wss://amilyservice.amily49.cc','apiUrl','registerMacro','[Amily2-翰林院]\x20RAG处理器已成功初始化','\x22\x20被点击','sendMessage','【监察系统】滑动后填表完成,UI\x20已刷新。','导入失败:'];_0x278f=function(){return _0x481bfa;};return _0x278f();}function importStyles(){const _0x2df74b=_0x3ce3,_0x104b19=document['createElement']('input');_0x104b19[_0x2df74b(0x8e)]='file',_0x104b19['accept']=_0x2df74b(0xf3),_0x104b19['style'][_0x2df74b(0x15d)]=_0x2df74b(0x17e);const _0x512c44=()=>{const _0x371668=_0x2df74b;document[_0x371668(0x151)][_0x371668(0x19b)](_0x104b19)&&document[_0x371668(0x151)][_0x371668(0xed)](_0x104b19);};_0x104b19[_0x2df74b(0x129)]=_0x8a8039=>{const _0x1550e8=_0x2df74b,_0x317ac6=_0x8a8039[_0x1550e8(0xf1)][_0x1550e8(0x124)][0x0];if(!_0x317ac6){_0x512c44();return;}const _0xe4c495=new FileReader();_0xe4c495[_0x1550e8(0xcc)]=_0x45f968=>{const _0x34b31b=_0x1550e8;try{const _0x76f1f8=JSON[_0x34b31b(0xe4)](_0x45f968[_0x34b31b(0xf1)][_0x34b31b(0x89)]);if(typeof _0x76f1f8!=='object'||Array[_0x34b31b(0x11b)](_0x76f1f8))throw new Error(_0x34b31b(0x15a));applyStyles(_0x76f1f8),saveStyles(_0x76f1f8),toastr[_0x34b31b(0x18d)](_0x34b31b(0xb5));}catch(_0x53ebe5){toastr['error'](_0x34b31b(0x10e)+_0x53ebe5[_0x34b31b(0xdd)],'错误');}finally{_0x512c44();}},_0xe4c495[_0x1550e8(0x11d)](_0x317ac6);},document[_0x2df74b(0x151)][_0x2df74b(0xdf)](_0x104b19),_0x104b19[_0x2df74b(0x13c)]();}function compareVersions(_0x10255e,_0x57f06f){const _0x524710=_0x3ce3,_0x10a7d2=_0x10255e['split']('.')[_0x524710(0xf2)](Number),_0x22fc16=_0x57f06f['split']('.')['map'](Number),_0x1a9328=Math[_0x524710(0x19e)](_0x10a7d2[_0x524710(0x97)],_0x22fc16[_0x524710(0x97)]);for(let _0x1499b0=0x0;_0x1499b0<_0x1a9328;_0x1499b0++){const _0x100e90=_0x10a7d2[_0x1499b0]||0x0,_0x575e77=_0x22fc16[_0x1499b0]||0x0;if(_0x100e90>_0x575e77)return!![];if(_0x100e90<_0x575e77)return![];}return![];}async function handleUpdateCheck(){const _0x5c9d18=_0x3ce3;console[_0x5c9d18(0xa3)](_0x5c9d18(0xf6));const _0x5ad03e=await checkForUpdates();if(_0x5ad03e&&_0x5ad03e[_0x5c9d18(0x10f)]){const _0x1a9ab8=compareVersions(_0x5ad03e[_0x5c9d18(0x10f)],pluginVersion);_0x1a9ab8?console[_0x5c9d18(0xa3)](_0x5c9d18(0x126)+_0x5ad03e['version']+_0x5c9d18(0x172)):console[_0x5c9d18(0xa3)](_0x5c9d18(0x179)),setUpdateInfo(_0x1a9ab8,_0x5ad03e),applyUpdateIndicator();}}async function handleMessageBoard(){const _0x544d47=async()=>{const _0x1a405e=_0x3ce3;try{const _0x69090f=await fetchMessageBoardContent();if(_0x69090f&&_0x69090f['message']){const _0x528b7a=$(_0x1a405e(0x92)),_0x25843c=$(_0x1a405e(0xde));_0x25843c[_0x1a405e(0x104)](_0x69090f['message']),_0x528b7a[_0x1a405e(0xc2)](),console[_0x1a405e(0xa3)](_0x1a405e(0x96));}}catch(_0x1f0846){console[_0x1a405e(0xe3)](_0x1a405e(0xa4),_0x1f0846);}};await _0x544d47(),setInterval(_0x544d47,0xea60);}function loadPluginStyles(){const _0x26e600=_0x3ce3,_0x3b44ec=_0xf57d3f=>{const _0x226c4c=_0x3ce3,_0x245262=_0x226c4c(0xd8)+_0xf57d3f[_0x226c4c(0xb1)]('.')[0x0];if(document[_0x226c4c(0x186)](_0x245262))return;const _0xeba667=_0x226c4c(0x19c)+extensionName+_0x226c4c(0xec)+_0xf57d3f+_0x226c4c(0xd6)+Date[_0x226c4c(0x160)](),_0x3b5b89=document[_0x226c4c(0x11f)](_0x226c4c(0x9a));_0x3b5b89['id']=_0x245262,_0x3b5b89['rel']='stylesheet',_0x3b5b89[_0x226c4c(0x8e)]=_0x226c4c(0xc4),_0x3b5b89['href']=_0xeba667,document[_0x226c4c(0xe7)][_0x226c4c(0xdf)](_0x3b5b89),console[_0x226c4c(0xa3)](_0x226c4c(0x8b)+_0xf57d3f);};_0x3b44ec(_0x26e600(0xae)),_0x3b44ec(_0x26e600(0x156)),_0x3b44ec(_0x26e600(0xbb)),_0x3b44ec(_0x26e600(0x173)),_0x3b44ec(_0x26e600(0xc7)),_0x3b44ec(_0x26e600(0xe9)),_0x3b44ec('renderer.css'),_0x3b44ec('iframe-renderer.css');const _0x5202f8='cwb-feature-style';if(!document[_0x26e600(0x186)](_0x5202f8)){const _0x12073c=document[_0x26e600(0x11f)](_0x26e600(0x9a));_0x12073c['id']=_0x5202f8,_0x12073c[_0x26e600(0xa8)]=_0x26e600(0x118),_0x12073c['type']=_0x26e600(0xc4),_0x12073c[_0x26e600(0x139)]=_0x26e600(0x19c)+extensionName+_0x26e600(0xce)+Date['now'](),document[_0x26e600(0xe7)][_0x26e600(0xdf)](_0x12073c),console[_0x26e600(0xa3)](_0x26e600(0x12a));}const _0x5e4941=_0x26e600(0xc0);if(!document['getElementById'](_0x5e4941)){const _0x2bcc46=document[_0x26e600(0x11f)]('link');_0x2bcc46['id']=_0x5e4941,_0x2bcc46['rel']=_0x26e600(0x118),_0x2bcc46[_0x26e600(0x8e)]='text/css',_0x2bcc46['href']=_0x26e600(0x19c)+extensionName+'/WorldEditor/WorldEditor.css?v='+Date[_0x26e600(0x160)](),document[_0x26e600(0xe7)][_0x26e600(0xdf)](_0x2bcc46),console['log'](_0x26e600(0x11a));}}window[_0x169b9e(0xdb)](_0x169b9e(0xdd),function(_0x36bec6){const _0x186dd9=_0x169b9e;if(_0x36bec6[_0x186dd9(0x9e)]&&_0x36bec6[_0x186dd9(0x9e)][_0x186dd9(0x8e)]==='getAvatars'){if(window[_0x186dd9(0xfb)])return;const _0x3f38d3=_0x186dd9(0xf7)+(getContext()[_0x186dd9(0x8a)]?.[_0x186dd9(0x9d)]??''),_0x22341b=_0x186dd9(0xf7)+(getContext()[_0x186dd9(0x17b)][this_chid]?.['avatar']??'');_0x36bec6[_0x186dd9(0x13f)]['postMessage']({'source':_0x186dd9(0x17d),'type':_0x186dd9(0xef),'urls':{'user':_0x3f38d3,'char':_0x22341b}},'*');return;}if(_0x36bec6['data']&&_0x36bec6[_0x186dd9(0x9e)][_0x186dd9(0x13f)]===_0x186dd9(0xcd)){const {action:_0x59fc9c,detail:_0x22b182}=_0x36bec6[_0x186dd9(0x9e)];console[_0x186dd9(0xa3)](_0x186dd9(0xd0)+_0x59fc9c,_0x22b182);switch(_0x59fc9c){case _0x186dd9(0x10c):_0x22b182&&_0x22b182[_0x186dd9(0xdd)]&&($(_0x186dd9(0xdc))[_0x186dd9(0xbe)](_0x22b182['message'])[_0x186dd9(0x16f)](_0x186dd9(0xca)),$(_0x186dd9(0x12d))[_0x186dd9(0x16f)](_0x186dd9(0x13c)),console[_0x186dd9(0xa3)](_0x186dd9(0xd3)+_0x22b182[_0x186dd9(0xdd)]));break;case'showToast':if(_0x22b182&&_0x22b182[_0x186dd9(0xdd)]&&window[_0x186dd9(0x86)]){const _0x5dfca5=_0x22b182['type']||_0x186dd9(0xa7);typeof window[_0x186dd9(0x86)][_0x5dfca5]===_0x186dd9(0x106)&&window[_0x186dd9(0x86)][_0x5dfca5](_0x22b182['message'],_0x22b182[_0x186dd9(0x112)]||'通知');}break;case _0x186dd9(0x12f):console[_0x186dd9(0xa3)]('[Amily2-主窗口]\x20按钮被点击:',_0x22b182);window['toastr']&&window[_0x186dd9(0x86)][_0x186dd9(0xa7)](_0x186dd9(0xd9)+(_0x22b182[_0x186dd9(0x144)]||'未知')+_0x186dd9(0x10b),_0x186dd9(0x19a));break;default:console[_0x186dd9(0xb7)](_0x186dd9(0x184)+_0x59fc9c);}}}),window['addEventListener'](_0x169b9e(0xe3),_0x5c79ad=>{const _0x1f3537=_0x169b9e,_0x26638a=_0x5c79ad['error']?.[_0x1f3537(0xd4)]||'';_0x26638a[_0x1f3537(0x189)](_0x1f3537(0x163))&&(console[_0x1f3537(0xe3)](_0x1f3537(0xd5),_0x5c79ad[_0x1f3537(0xe3)]),toastr[_0x1f3537(0xe3)](_0x1f3537(0x187)+(_0x5c79ad[_0x1f3537(0xe3)]?.['message']||_0x1f3537(0xa1)),_0x1f3537(0x103),{'timeOut':0x2710}));}),jQuery(async()=>{const _0x112550=_0x169b9e;console['log'](_0x112550(0xf8)),initializeApiListener(),registerApiHandler(_0x112550(0x154),async _0x49f8a3=>{const _0x3a36f7=_0x112550;return amilyHelper[_0x3a36f7(0x154)](_0x49f8a3['range'],_0x49f8a3[_0x3a36f7(0xc6)]);}),registerApiHandler(_0x112550(0x18c),async _0x8d9f59=>{const _0xb5b44e=_0x112550;return await amilyHelper[_0xb5b44e(0x18c)](_0x8d9f59['messages'],_0x8d9f59[_0xb5b44e(0xc6)]);}),registerApiHandler(_0x112550(0x183),async _0x58feb8=>{const _0x2573cf=_0x112550,_0x14992a=_0x58feb8['field_values']||_0x58feb8[_0x2573cf(0x140)],_0x5e5820=_0x58feb8[_0x2573cf(0x14b)]!==undefined?_0x58feb8[_0x2573cf(0x14b)]:_0x58feb8[_0x2573cf(0x143)],_0x3fb4ef=_0x58feb8[_0x2573cf(0xc6)]||{};return console['log']('[Amily2-API]\x20setChatMessage\x20收到参数:',{'field_values':_0x14992a,'message_id':_0x5e5820,'options':_0x3fb4ef,'raw_data':_0x58feb8}),await amilyHelper[_0x2573cf(0x183)](_0x14992a,_0x5e5820,_0x3fb4ef);}),registerApiHandler(_0x112550(0x101),async _0x4d4cdf=>{const _0xb2868c=_0x112550;return await amilyHelper[_0xb2868c(0x101)](_0x4d4cdf[_0xb2868c(0x16c)],_0x4d4cdf['options']);}),registerApiHandler(_0x112550(0x15c),async _0x8cc21e=>{const _0x263fba=_0x112550;return await amilyHelper['deleteChatMessages'](_0x8cc21e[_0x263fba(0x197)],_0x8cc21e['options']);}),registerApiHandler(_0x112550(0x174),async _0x59a202=>{return await amilyHelper['getLorebooks']();}),registerApiHandler(_0x112550(0x12b),async _0x595987=>{const _0x5993f0=_0x112550;return await amilyHelper['getCharLorebooks'](_0x595987[_0x5993f0(0xc6)]);}),registerApiHandler(_0x112550(0x105),async _0x5cd1ac=>{const _0x39b449=_0x112550;return await amilyHelper[_0x39b449(0x105)](_0x5cd1ac['bookName']);}),registerApiHandler('setLorebookEntries',async _0x2bd175=>{const _0x2cc4c0=_0x112550;return await amilyHelper['setLorebookEntries'](_0x2bd175['bookName'],_0x2bd175[_0x2cc4c0(0x13d)]);}),registerApiHandler(_0x112550(0xb4),async _0x214b92=>{const _0x17658b=_0x112550;return await amilyHelper[_0x17658b(0xb4)](_0x214b92[_0x17658b(0xb2)],_0x214b92[_0x17658b(0x13d)]);}),registerApiHandler('createLorebook',async _0x3adde=>{const _0x3e8940=_0x112550;return await amilyHelper[_0x3e8940(0xe1)](_0x3adde[_0x3e8940(0xb2)]);}),registerApiHandler(_0x112550(0x146),async _0x4e4180=>{const _0x3fe483=_0x112550;return await amilyHelper[_0x3fe483(0x146)](_0x4e4180[_0x3fe483(0xb3)]);}),registerApiHandler(_0x112550(0x169),async _0x2a8f3b=>{const _0x220096=_0x112550;return amilyHelper[_0x220096(0x169)]();}),registerApiHandler('toastr',async _0x184d3f=>{const _0x2ad3ab=_0x112550;return window[_0x2ad3ab(0x86)]&&typeof window[_0x2ad3ab(0x86)][_0x184d3f[_0x2ad3ab(0x8e)]]===_0x2ad3ab(0x106)&&window[_0x2ad3ab(0x86)][_0x184d3f[_0x2ad3ab(0x8e)]](_0x184d3f[_0x2ad3ab(0xdd)],_0x184d3f[_0x2ad3ab(0x112)]),!![];}),registerApiHandler(_0x112550(0x150),async _0xdc634=>{const _0x58c5a5=_0x112550,{messageIndex:_0x5abb04,swipeIndex:_0x945f02}=_0xdc634,_0x9b82b4=await amilyHelper[_0x58c5a5(0x154)](_0x5abb04,{'include_swipes':!![]});if(_0x9b82b4&&_0x9b82b4['length']>0x0&&_0x9b82b4[0x0][_0x58c5a5(0x14a)]){const _0x105fa8=_0x9b82b4[0x0][_0x58c5a5(0x14a)][_0x945f02];if(_0x105fa8!==undefined){await amilyHelper[_0x58c5a5(0x18c)]([{'message_id':_0x5abb04,'message':_0x105fa8}],{'refresh':'affected'});const _0xa6b3ae=getContext();return _0xa6b3ae[_0x58c5a5(0x176)][_0x5abb04]&&(_0xa6b3ae[_0x58c5a5(0x176)][_0x5abb04][_0x58c5a5(0x110)]=_0x945f02),{'success':!![],'message':_0x58c5a5(0xaa)+_0x945f02};}}throw new Error('无法切换到开场白\x20'+_0x945f02);}),initializeAmilyHelper(),console[_0x112550(0xa3)](_0x112550(0xf8));!extension_settings[extensionName]&&(extension_settings[extensionName]={});const _0x2b2528={...defaultSettings,...tableSystemDefaultSettings,...cwbDefaultSettings,'render_on_every_message':![],'amily_render_enabled':![]};for(const _0x278f26 in _0x2b2528){extension_settings[extensionName][_0x278f26]===undefined&&(extension_settings[extensionName][_0x278f26]=_0x2b2528[_0x278f26]);}console['log']('[Amily2号-帝国枢密院]\x20帝国基本法已确认,档案室已与国库对接完毕。');let _0x39ace3=0x0;const _0x1eb1b3=0x64,_0x346f23=0x64,_0xc81b8e=_0x112550(0x123),_0x3ad4b3=setInterval(async()=>{const _0x26c102=_0x112550;if($(_0xc81b8e)[_0x26c102(0x97)]>0x0){clearInterval(_0x3ad4b3),console[_0x26c102(0xa3)](_0x26c102(0x161));try{console[_0x26c102(0xa3)](_0x26c102(0x177)),loadPluginStyles(),console[_0x26c102(0xa3)](_0x26c102(0xa9)),await registerSlashCommands(),console[_0x26c102(0xa3)](_0x26c102(0x16e)),createDrawer();function _0x2996fb(){let _0x39e16a=0x0;const _0x416727=0x32,_0x27be83=0x64,_0x54355f=setInterval(()=>{const _0x1e2982=_0x3ce3,_0x330cf9=document['getElementById'](_0x1e2982(0x9c));if(_0x330cf9){clearInterval(_0x54355f);try{console['log'](_0x1e2982(0xa2)),bindGlossaryEvents(),console[_0x1e2982(0xa3)](_0x1e2982(0x18e));}catch(_0x543023){console[_0x1e2982(0xe3)](_0x1e2982(0x91),_0x543023);}}else _0x39e16a++,_0x39e16a>=_0x416727&&(clearInterval(_0x54355f),console[_0x1e2982(0xe3)](_0x1e2982(0xcb)));},_0x27be83);}_0x2996fb();function _0x28dcff(){let _0x41b309=0x0;const _0x391c7a=0x32,_0x110bff=0x64,_0x1a0ccd=setInterval(async()=>{const _0x1ab22f=_0x3ce3,_0x11b0eb=$('#amily2_character_world_book_panel');if(_0x11b0eb[_0x1ab22f(0x97)]>0x0){clearInterval(_0x1a0ccd);try{console['log'](_0x1ab22f(0xfe)),await initializeCharacterWorldBook(_0x11b0eb),console[_0x1ab22f(0xa3)](_0x1ab22f(0xe5));}catch(_0x332238){console[_0x1ab22f(0xe3)]('!!!【角色世界书构建失败】:',_0x332238);}}else _0x41b309++,_0x41b309>=_0x391c7a&&(clearInterval(_0x1a0ccd),console[_0x1ab22f(0xe3)]('!!!【角色世界书构建失败】:\x20等待面板\x20#amily2_character_world_book_panel\x20超时。'));},_0x110bff);}_0x28dcff(),console['log']('[Amily2号-开国大典]\x20步骤3.8:注册表格占位符宏...');try{const _0x5998ba=getContext();_0x5998ba&&typeof _0x5998ba['registerMacro']===_0x26c102(0x106)?(_0x5998ba[_0x26c102(0x109)]('Amily2EditContent',()=>{const _0x3ca309=_0x26c102,_0x28910f=generateTableContent();return _0x28910f&&(window[_0x3ca309(0x149)]=!![]),_0x28910f;}),console[_0x26c102(0xa3)]('[Amily2-核心引擎]\x20已成功注册表格占位符宏:\x20{{Amily2EditContent}}')):console[_0x26c102(0xb7)](_0x26c102(0x8c));}catch(_0x3bc957){console[_0x26c102(0xe3)](_0x26c102(0xac),_0x3bc957);}console[_0x26c102(0xa3)](_0x26c102(0x134));let _0x23dfe4=![];async function _0x20d422(_0x5db41f,_0x142c94,_0x4a163b){const _0x37cf46=_0x26c102;clearUpdatedTables(),console[_0x37cf46(0xa3)](_0x37cf46(0x175),{'type':_0x5db41f,'params':_0x142c94,'dryRun':_0x4a163b,'isProcessing':_0x23dfe4});if(_0x5db41f===_0x37cf46(0xbf)||_0x23dfe4||_0x4a163b){console[_0x37cf46(0xa3)](_0x37cf46(0x120),{'type':_0x5db41f,'isProcessing':_0x23dfe4,'dryRun':_0x4a163b});return;}const _0x5824f8=extension_settings[extensionName];if(_0x5824f8?.[_0x37cf46(0x14c)]===![])return;const _0x415e3a=_0x5824f8?.[_0x37cf46(0x16b)]===!![],_0x79a5a9=!!_0x5824f8?.[_0x37cf46(0x108)]||!!_0x5824f8?.[_0x37cf46(0x15b)];if(!_0x415e3a&&!_0x79a5a9){console[_0x37cf46(0xa3)]('[Amily2-剧情优化]\x20优化已启用,但Jqyh\x20API已禁用且主页API未配置。');return;}_0x23dfe4=!![];let _0xdb246b=null;const _0x494812={'isCancelled':![]};try{const _0x380ba4=$(_0x37cf46(0xdc))[_0x37cf46(0xbe)]();if(!_0x380ba4)return _0x23dfe4=![],![];const _0x331064=_0x37cf46(0x194);let _0x374331;const _0x22b6b0=new Promise((_0x2cbc99,_0x147500)=>{_0x374331=_0x147500;});_0xdb246b=toastr['info'](_0x331064,_0x37cf46(0x167),{'timeOut':0x0,'extendedTimeOut':0x0,'tapToDismiss':![],'onclick':null,'escapeHtml':![],'onShown':function(){const _0x4619d7=_0x37cf46;$(_0x4619d7(0xc9))[_0x4619d7(0x166)]('click',function(_0x5e5961){const _0x2d8046=_0x4619d7;_0x5e5961[_0x2d8046(0xf9)](),_0xdb246b&&(_0xdb246b[_0x2d8046(0x93)](),_0xdb246b=null),_0x494812[_0x2d8046(0x18f)]=!![],_0x374331(new Error(_0x2d8046(0xf0)));});}});const _0x1232b5=getContext(),_0x5afa66=_0x5824f8[_0x37cf46(0x116)]||0xa;let _0x171444=[];_0x5afa66>0x0&&(_0x171444=_0x1232b5[_0x37cf46(0x176)][_0x37cf46(0x16d)](-_0x5afa66));const _0xf99809=processPlotOptimization({'mes':_0x380ba4},_0x171444,_0x494812),_0x1762ac=await Promise[_0x37cf46(0x17c)]([_0xf99809,_0x22b6b0]);if(_0x1762ac&&_0x1762ac[_0x37cf46(0x159)]){const _0x48a8c3=$(_0x37cf46(0xdc))[_0x37cf46(0xbe)](),_0x4617ea=_0x48a8c3+'\x0a'+_0x1762ac[_0x37cf46(0x159)];$(_0x37cf46(0xdc))[_0x37cf46(0xbe)](_0x4617ea)[_0x37cf46(0x16f)]('input'),toastr[_0x37cf46(0x18d)](_0x37cf46(0x113),'操作成功');}else console[_0x37cf46(0xa3)](_0x37cf46(0x117));return![];}catch(_0x22d340){return _0x22d340[_0x37cf46(0xdd)]===_0x37cf46(0xf0)?(console[_0x37cf46(0xa3)]('[Amily2-剧情优化]\x20优化流程已被用户中止。发送原始消息。'),toastr[_0x37cf46(0xc8)](_0x37cf46(0xe6),_0x37cf46(0xb0),{'timeOut':0x7d0})):(console[_0x37cf46(0xe3)](_0x37cf46(0xd7),_0x22d340),toastr[_0x37cf46(0xe3)](_0x37cf46(0x180),'错误')),![];}finally{_0x23dfe4=![],_0xdb246b&&(toastr[_0x37cf46(0xd1)](_0xdb246b),_0xdb246b=null);}}!window['amily2EventsRegistered']&&(eventSource['on'](event_types['GENERATION_AFTER_COMMANDS'],_0x20d422),eventSource['on'](event_types[_0x26c102(0xc5)],onMessageReceived),eventSource['on'](event_types[_0x26c102(0x16a)],onMessageReceived),eventSource['on'](event_types[_0x26c102(0xc5)],_0x1c6aa0=>handleTableUpdate(_0x1c6aa0)),eventSource['on'](event_types[_0x26c102(0xee)],async _0x55a42f=>{const _0x144e0c=_0x26c102,_0x4a9482=getContext();if(_0x4a9482[_0x144e0c(0x176)][_0x144e0c(0x97)]<0x2){log(_0x144e0c(0x95),_0x144e0c(0xa7));return;}log('【监察系统】检测到消息滑动\x20(SWIPED),开始执行状态回退...',_0x144e0c(0xb7)),rollbackState();const _0x236854=_0x4a9482[_0x144e0c(0x176)][_0x55a42f]||_0x4a9482[_0x144e0c(0x176)][_0x4a9482['chat'][_0x144e0c(0x97)]-0x1];if(_0x236854[_0x144e0c(0x94)]){log(_0x144e0c(0x18a),_0x144e0c(0xa7)),renderTables();return;}const _0x5bf6b5=extension_settings[extensionName],_0x3d5d19=_0x5bf6b5[_0x144e0c(0x192)]||'main-api';if(_0x3d5d19==='main-api')log(_0x144e0c(0x15e)+_0x55a42f+'。','info'),await handleTableUpdate(_0x55a42f,!![]);else _0x3d5d19===_0x144e0c(0x136)||_0x3d5d19===_0x144e0c(0xb6)?(log(_0x144e0c(0x141),_0x144e0c(0xa7)),await fillWithSecondaryApi(_0x236854,!![])):log(_0x144e0c(0x12e),_0x144e0c(0xa7));renderTables(),log(_0x144e0c(0x10d),_0x144e0c(0x18d));}),eventSource['on'](event_types['MESSAGE_EDITED'],_0x5811c1=>{handleTableUpdate(_0x5811c1),updateOrInsertTableInChat();}),eventSource['on'](event_types[_0x26c102(0x185)],()=>{const _0x1dd81d=_0x26c102;window['lastPreOptimizationResult']=null,document[_0x1dd81d(0x170)](new CustomEvent(_0x1dd81d(0x142))),manageLorebookEntriesForChat(),setTimeout(()=>{const _0x2e69e4=_0x1dd81d;log(_0x2e69e4(0x90),_0x2e69e4(0xa7)),clearHighlights(),clearUpdatedTables(),loadTables(),renderTables(),extension_settings[extensionName][_0x2e69e4(0x99)]?startContinuousRendering():stopContinuousRendering();},0x64);}),eventSource['on'](event_types[_0x26c102(0xe0)],(_0x144d53,_0x541447)=>{const _0x456c36=_0x26c102;log('【监察系统】检测到消息\x20'+_0x541447+_0x456c36(0x85),_0x456c36(0xb7)),clearHighlights(),loadTables(_0x541447),renderTables();}),eventSource['on'](event_types[_0x26c102(0xc5)],updateOrInsertTableInChat),eventSource['on'](event_types[_0x26c102(0x193)],updateOrInsertTableInChat),window['amily2EventsRegistered']=!![]);console[_0x26c102(0xa3)](_0x26c102(0x15f));try{_0x4ccd67(),console[_0x26c102(0xa3)](_0x26c102(0x10a));}catch(_0x3045bd){console['error'](_0x26c102(0x114),_0x3045bd);}console['log']('[Amily2号-开国大典]\x20步骤六:智能冲突检测与注入策略...');async function _0x239d89(..._0xc51884){const _0x5c66bc=_0x26c102;console['log'](_0x5c66bc(0xff),_0xc51884[0x0]?.[_0x5c66bc(0x97)]||0x0,')');try{await injectTableData(..._0xc51884);}catch(_0x370236){console[_0x5c66bc(0xe3)](_0x5c66bc(0x171),_0x370236);}if(window[_0x5c66bc(0x11c)]&&typeof window[_0x5c66bc(0x11c)][_0x5c66bc(0xea)]===_0x5c66bc(0x106))try{console[_0x5c66bc(0xa3)](_0x5c66bc(0x14e)),await window[_0x5c66bc(0x11c)]['rearrangeChat'](..._0xc51884);}catch(_0x1013cd){console['error'](_0x5c66bc(0xf5),_0x1013cd);}}console[_0x26c102(0xa3)]('[Amily2-策略]\x20采用“完全主导”策略,覆盖\x20`vectors_rearrangeChat`。'),window['vectors_rearrangeChat']=_0x239d89,window[_0x26c102(0x9f)]&&(window['amily2HanlinyuanInjector']=null),console[_0x26c102(0xa3)]('【Amily2号】帝国秩序已完美建立。Amily2号的府邸已恭候陛下的莅临。'),console['log'](_0x26c102(0x14d)),typeof window[_0x26c102(0x131)]!==_0x26c102(0x155)?setTimeout(()=>{const _0x1fcc7a=_0x26c102;console['log']('[Amily2号-版本系统]\x20正在启动版本检测器...'),window[_0x1fcc7a(0x131)]['initialize']();},0x7d0):console[_0x26c102(0xb7)](_0x26c102(0x125)),handleUpdateCheck(),handleMessageBoard(),initializeOnlineTracker(),initializeRenderer(),extension_settings[extensionName]['render_on_every_message']&&startContinuousRendering(),setTimeout(()=>{const _0x3043bd=_0x26c102;try{loadAndApplyStyles();const _0x4a29cc=document['getElementById']('amily2-import-theme-btn'),_0x4a0e77=document[_0x3043bd(0x186)](_0x3043bd(0xba)),_0x32554f=document[_0x3043bd(0x186)](_0x3043bd(0x19d));if(_0x4a29cc)_0x4a29cc[_0x3043bd(0xdb)](_0x3043bd(0x13c),importStyles);if(_0x4a0e77)_0x4a0e77[_0x3043bd(0xdb)](_0x3043bd(0x13c),exportStyles);if(_0x32554f)_0x32554f[_0x3043bd(0xdb)](_0x3043bd(0x13c),resetToDefaultStyles);log(_0x3043bd(0x195),_0x3043bd(0x18d));}catch(_0x4dd785){log(_0x3043bd(0xf4)+_0x4dd785,_0x3043bd(0xe3));}},0x1f4);}catch(_0x1fca21){console[_0x26c102(0xe3)](_0x26c102(0x162),_0x1fca21);}}else _0x39ace3++,_0x39ace3>=_0x1eb1b3&&(clearInterval(_0x3ad4b3),console[_0x26c102(0xe3)]('[Amily2号]\x20部署失败:等待\x20'+_0xc81b8e+_0x26c102(0x17a)));},_0x346f23);});function initializeOnlineTracker(){const _0x28762e=_0x169b9e,_0x573a3b=_0x28762e(0x107);let _0x304890,_0x5b746c;function _0x1b2149(){const _0x25361d=_0x28762e,_0x17ed2f=$('#amily2_drawer_content');if(_0x17ed2f['length']===0x0||!_0x17ed2f[_0x25361d(0x9e)]('initialized')){setTimeout(_0x1b2149,0x3e8);return;}if($('#amily2-online-tracker')['length']>0x0)return;const _0x4d0fb8=$(_0x25361d(0x18b));_0x4d0fb8[_0x25361d(0x104)](_0x25361d(0x135)),_0x17ed2f[_0x25361d(0xa0)](_0x4d0fb8),_0x64bafa();}function _0x64bafa(){const _0x164a45=_0x28762e;try{_0x304890=new WebSocket(_0x573a3b),_0x304890['onopen']=()=>{const _0x482c62=_0x3ce3;console[_0x482c62(0xa3)]('[Amily2-在线统计]\x20已连接到服务器'),_0x5b746c&&(clearInterval(_0x5b746c),_0x5b746c=null);},_0x304890[_0x164a45(0xb9)]=_0x3de188=>{const _0x2ab6e9=_0x164a45;try{const _0x24188=JSON[_0x2ab6e9(0xe4)](_0x3de188[_0x2ab6e9(0x9e)]);_0x24188[_0x2ab6e9(0x8e)]===_0x2ab6e9(0x11e)&&$('#amily2-online-count')[_0x2ab6e9(0x153)](_0x24188[_0x2ab6e9(0x111)]+_0x2ab6e9(0x190));}catch(_0x104abb){console['error']('[Amily2-在线统计]\x20解析消息失败:',_0x104abb);}},_0x304890[_0x164a45(0x13b)]=()=>{const _0x5dba0e=_0x164a45;console[_0x5dba0e(0xa3)](_0x5dba0e(0x158)),$(_0x5dba0e(0xab))[_0x5dba0e(0x153)]('离线'),!_0x5b746c&&(_0x5b746c=setInterval(_0x64bafa,0x1388));},_0x304890[_0x164a45(0x164)]=_0x34de60=>{const _0x4dbc13=_0x164a45;console[_0x4dbc13(0xb7)](_0x4dbc13(0xbd),_0x34de60),_0x304890['close']();};}catch(_0x374491){console[_0x164a45(0xe3)]('[Amily2-在线统计]\x20初始化失败:',_0x374491);}}_0x1b2149();}