diff --git a/index.js b/index.js index d829f66..93d0f3d 100644 --- a/index.js +++ b/index.js @@ -1,147 +1 @@ -import { createDrawer } from "./ui/drawer.js"; -import "./MiZheSi/index.js"; // 【密折司】独立模块 -import { registerSlashCommands } from "./core/commands.js"; -import { onMessageReceived, onChatChanged } from "./core/events.js"; -import { eventSource, event_types } 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 { extension_settings } from '/scripts/extensions.js'; - - -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 messageData = await fetchMessageBoardContent(); - if (messageData && messageData.message) { - const messageBoard = $('#amily2_message_board'); - const messageContent = $('#amily2_message_content'); - - // 使用 .html() 来正确渲染可能包含的 HTML 标签 - messageContent.html(messageData.message); - messageBoard.show(); - console.log("【Amily2号-内务府】已成功获取并展示来自陛下的最新圣谕。"); - } -} - - -// 【强化版】皇家制衣官 -function loadPluginStyles() { - // 这是一个可复用的内部律法,用于为任何一件华服(CSS文件)赋予生命 - 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"); // 【第三道圣谕】为翰林院披上其专属华服 -} - - -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号-帝国枢密院] 开始执行开国大典..."); - - if (!extension_settings[extensionName]) { - extension_settings[extensionName] = {}; - } - Object.assign(extension_settings[extensionName], { - ...defaultSettings, - ...extension_settings[extensionName], - }); - 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(); - - console.log("[Amily2号-开国大典] 步骤四:部署帝国哨兵网络..."); - if (!window.amily2EventsRegistered) { - eventSource.on(event_types.MESSAGE_RECEIVED, onMessageReceived); - eventSource.on(event_types.IMPERSONATE_READY, onMessageReceived); - eventSource.on(event_types.CHAT_CHANGED, onChatChanged); - window.amily2EventsRegistered = true; - } - - console.log("【Amily2号】帝国秩序已完美建立。Amily2号的府邸已恭候陛下的莅临。"); - - handleUpdateCheck(); - handleMessageBoard(); - - } catch (error) { - console.error("!!!【开国大典失败】在执行系列法令时发生严重错误:", error); - } - - } else { - attempts++; - if (attempts >= maxAttempts) { - clearInterval(deploymentInterval); - console.error(`[Amily2号] 部署失败:等待 ${targetSelector} 超时。`); - } - } - }, checkInterval); -}); +(function(_0x3e0000,_0x542d55){const _0x3d7615=_0x2a15,_0x2a4294=_0x3e0000();while(!![]){try{const _0x7ac49a=-parseInt(_0x3d7615(0x1f3))/0x1+parseInt(_0x3d7615(0x1ef))/0x2+-parseInt(_0x3d7615(0x1f6))/0x3+parseInt(_0x3d7615(0x1ff))/0x4+parseInt(_0x3d7615(0x1ea))/0x5+-parseInt(_0x3d7615(0x205))/0x6*(-parseInt(_0x3d7615(0x206))/0x7)+-parseInt(_0x3d7615(0x21e))/0x8;if(_0x7ac49a===_0x542d55)break;else _0x2a4294['push'](_0x2a4294['shift']());}catch(_0x7518de){_0x2a4294['push'](_0x2a4294['shift']());}}}(_0x1b29,0xc717d));import{createDrawer}from'./ui/drawer.js';import'./MiZheSi/index.js';import{registerSlashCommands}from'./core/commands.js';import{onMessageReceived,onChatChanged}from'./core/events.js';import{eventSource,event_types}from'/script.js';import{checkForUpdates,fetchMessageBoardContent}from'./core/api.js';function _0x2a15(_0x3aea5b,_0x46b594){const _0x1b29dc=_0x1b29();return _0x2a15=function(_0x2a155d,_0x125f10){_0x2a155d=_0x2a155d-0x1e9;let _0xa04099=_0x1b29dc[_0x2a155d];return _0xa04099;},_0x2a15(_0x3aea5b,_0x46b594);}import{setUpdateInfo,applyUpdateIndicator}from'./ui/state.js';function _0x1b29(){const _0x5d2a6f=['map','Amily2插件错误:\x20','2301490lKWIHY','length','[Amily2号-开国大典]\x20步骤一:为宫殿披上华服...','max','566266KgxVfc','rel','MESSAGE_RECEIVED','347034JPplln','scripts/extensions/third-party/','[Amily2号-开国大典]\x20步骤四:部署帝国哨兵网络...','[Amily2号-开国大典]\x20步骤三:开始召唤府邸...','[Amily2号-皇家制衣局]\x20已为帝国披上华服:\x20','[Amily2号-开国大典]\x20步骤二:皇家仪仗队就位...','includes','style.css','assign','786012etyZhU','now','stack','hanlinyuan.css','[Amily2号]\x20部署失败:等待\x20','historiography.css','66ngkyKh','502943XFWqJt','show','createElement','href','appendChild','head','\x20超时。','split','严重错误','/assets/','error','text/css','【Amily2号-情报部】捷报!发现新版本:\x20','【Amily2号】帝国秩序已完美建立。Amily2号的府邸已恭候陛下的莅临。','#sys-settings-button','message','stylesheet','version','IMPERSONATE_READY','type','[Amily2-全局卫队]\x20捕获到严重错误:','#amily2_message_content','未知错误','【Amily2号】帝国已就绪,现派遣外交官,为陛下探查外界新情报...','11446560iTwEIC','。情报已转交内务府。','?v=','log','amily2EventsRegistered','3953310ViGWKM','【Amily2号-内务府】已成功获取并展示来自陛下的最新圣谕。','[Amily2号-帝国枢密院]\x20开始执行开国大典...'];_0x1b29=function(){return _0x5d2a6f;};return _0x1b29();}import{pluginVersion,extensionName,defaultSettings}from'./utils/settings.js';import{extension_settings}from'/scripts/extensions.js';function compareVersions(_0xcb9355,_0x125053){const _0x467e74=_0x2a15,_0x99def9=_0xcb9355[_0x467e74(0x20d)]('.')['map'](Number),_0x11dfa4=_0x125053[_0x467e74(0x20d)]('.')[_0x467e74(0x1ed)](Number),_0x29b161=Math[_0x467e74(0x1f2)](_0x99def9[_0x467e74(0x1f0)],_0x11dfa4['length']);for(let _0x4abbb0=0x0;_0x4abbb0<_0x29b161;_0x4abbb0++){const _0x2f5bdd=_0x99def9[_0x4abbb0]||0x0,_0x495bd2=_0x11dfa4[_0x4abbb0]||0x0;if(_0x2f5bdd>_0x495bd2)return!![];if(_0x2f5bdd<_0x495bd2)return![];}return![];}async function handleUpdateCheck(){const _0x48000a=_0x2a15;console[_0x48000a(0x221)](_0x48000a(0x21d));const _0x228beb=await checkForUpdates();if(_0x228beb&&_0x228beb[_0x48000a(0x217)]){const _0x23ff24=compareVersions(_0x228beb[_0x48000a(0x217)],pluginVersion);_0x23ff24?console[_0x48000a(0x221)](_0x48000a(0x212)+_0x228beb[_0x48000a(0x217)]+_0x48000a(0x21f)):console[_0x48000a(0x221)]('【Amily2号-情报部】一切安好,帝国已是最新版本。情报已转交内务府备案。'),setUpdateInfo(_0x23ff24,_0x228beb),applyUpdateIndicator();}}async function handleMessageBoard(){const _0x44dfb2=_0x2a15,_0x17433e=await fetchMessageBoardContent();if(_0x17433e&&_0x17433e[_0x44dfb2(0x215)]){const _0x59b8c9=$('#amily2_message_board'),_0x5c9130=$(_0x44dfb2(0x21b));_0x5c9130['html'](_0x17433e[_0x44dfb2(0x215)]),_0x59b8c9[_0x44dfb2(0x207)](),console[_0x44dfb2(0x221)](_0x44dfb2(0x1eb));}}function loadPluginStyles(){const _0x5a217b=_0x2a15,_0x557d62=_0x21d11a=>{const _0x3897e5=_0x2a15,_0x41241c='amily2-style-'+_0x21d11a[_0x3897e5(0x20d)]('.')[0x0];if(document['getElementById'](_0x41241c))return;const _0x667df6=_0x3897e5(0x1f7)+extensionName+_0x3897e5(0x20f)+_0x21d11a+_0x3897e5(0x220)+Date[_0x3897e5(0x200)](),_0x5b1113=document[_0x3897e5(0x208)]('link');_0x5b1113['id']=_0x41241c,_0x5b1113[_0x3897e5(0x1f4)]=_0x3897e5(0x216),_0x5b1113[_0x3897e5(0x219)]=_0x3897e5(0x211),_0x5b1113[_0x3897e5(0x209)]=_0x667df6,document[_0x3897e5(0x20b)][_0x3897e5(0x20a)](_0x5b1113),console[_0x3897e5(0x221)](_0x3897e5(0x1fa)+_0x21d11a);};_0x557d62(_0x5a217b(0x1fd)),_0x557d62(_0x5a217b(0x204)),_0x557d62(_0x5a217b(0x202));}window['addEventListener']('error',_0x40ac7e=>{const _0x12e42d=_0x2a15,_0x338fb5=_0x40ac7e[_0x12e42d(0x210)]?.[_0x12e42d(0x201)]||'';_0x338fb5[_0x12e42d(0x1fc)]('ST-Amily2-Chat-Optimisation')&&(console['error'](_0x12e42d(0x21a),_0x40ac7e['error']),toastr[_0x12e42d(0x210)](_0x12e42d(0x1ee)+(_0x40ac7e[_0x12e42d(0x210)]?.[_0x12e42d(0x215)]||_0x12e42d(0x21c)),_0x12e42d(0x20e),{'timeOut':0x2710}));}),jQuery(async()=>{const _0x4b9d4f=_0x2a15;console[_0x4b9d4f(0x221)](_0x4b9d4f(0x1ec));!extension_settings[extensionName]&&(extension_settings[extensionName]={});Object[_0x4b9d4f(0x1fe)](extension_settings[extensionName],{...defaultSettings,...extension_settings[extensionName]}),console[_0x4b9d4f(0x221)]('[Amily2号-帝国枢密院]\x20帝国基本法已确认,档案室已与国库对接完毕。');let _0x53f348=0x0;const _0x156efe=0x64,_0x56877e=0x64,_0x327d7e=_0x4b9d4f(0x214),_0x23d150=setInterval(async()=>{const _0x13bd10=_0x4b9d4f;if($(_0x327d7e)[_0x13bd10(0x1f0)]>0x0){clearInterval(_0x23d150),console[_0x13bd10(0x221)]('[Amily2号-帝国枢密院]\x20SillyTavern宫殿主体已确认,开国大典正式开始!');try{console[_0x13bd10(0x221)](_0x13bd10(0x1f1)),loadPluginStyles(),console['log'](_0x13bd10(0x1fb)),await registerSlashCommands(),console[_0x13bd10(0x221)](_0x13bd10(0x1f9)),createDrawer(),console['log'](_0x13bd10(0x1f8)),!window[_0x13bd10(0x1e9)]&&(eventSource['on'](event_types[_0x13bd10(0x1f5)],onMessageReceived),eventSource['on'](event_types[_0x13bd10(0x218)],onMessageReceived),eventSource['on'](event_types['CHAT_CHANGED'],onChatChanged),window['amily2EventsRegistered']=!![]),console[_0x13bd10(0x221)](_0x13bd10(0x213)),handleUpdateCheck(),handleMessageBoard();}catch(_0x3026a8){console['error']('!!!【开国大典失败】在执行系列法令时发生严重错误:',_0x3026a8);}}else _0x53f348++,_0x53f348>=_0x156efe&&(clearInterval(_0x23d150),console[_0x13bd10(0x210)](_0x13bd10(0x203)+_0x327d7e+_0x13bd10(0x20c)));},_0x56877e);});