mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 17:05:50 +00:00
1 line
8.4 KiB
JavaScript
1 line
8.4 KiB
JavaScript
function _0x10c9(){const _0x44d6f3=['tabIndex','399531VLyadL','18860lwnLbk','chat','.mizhesi-message-block','length','expanded','show','siblings','CANCELLED','取消生成','GENERATE_AFTER_COMBINE_PROMPTS','fa-solid\x20fa-scroll','string','error','525448KauSgM','push','getElementById','1430397bXzkVx','56DtWFWT','closest','【密折司】解析修改后的JSON奏章失败:','35QUyBib','【密折司】无法找到左下角扩展菜单\x20(extensionsMenu)。','role','确认修改','val','info','toggleClass','miZheSiLaunchButton','log','content','Input\x20is\x20not\x20a\x20chat\x20array.','【密折司】错误:您的SillyTavern版本过旧,缺少必要的事件支持。请更新至最新版本。','template','click','find','className','classList','/MiZheSi','textarea','flexGap5','splice','forEach','append','addEventListener','isArray','parse','2148380wadiUD','extensionsMenu','fast','切换【密折司】状态','div','toggle','.mizhesi-message-header','【密折司】奏章已按御笔修改\x20(Text\x20Gen)。','\x22>\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<div\x20class=\x22mizhesi-message-header\x22>','title','关闭Amliy2号密折司','slideToggle','【密折司】已','appendChild','each','1956484aRIGxS','CHAT_COMPLETION_PROMPT_READY','prompt','span','complete','.mizhesi-message-content','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22mizhesi-message-block\x22\x20data-role=\x22','active','createElement','textContent','5183904jXZYHs','</div>\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<div\x20class=\x22mizhesi-message-content\x22>\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\x20\x20\x20\x20<textarea\x20class=\x22mizhesi-message-textarea\x22></textarea>\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</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','flex-container','amily2_miZheSiEnabled'];_0x10c9=function(){return _0x44d6f3;};return _0x10c9();}const _0x2b2f8f=_0xe56f;(function(_0xff6f5c,_0x26c27b){const _0x18b5a5=_0xe56f,_0x374099=_0xff6f5c();while(!![]){try{const _0x39ff2f=-parseInt(_0x18b5a5(0x1e7))/0x1*(parseInt(_0x18b5a5(0x220))/0x2)+-parseInt(_0x18b5a5(0x21f))/0x3+-parseInt(_0x18b5a5(0x210))/0x4+-parseInt(_0x18b5a5(0x201))/0x5+parseInt(_0x18b5a5(0x21a))/0x6+-parseInt(_0x18b5a5(0x1e0))/0x7+parseInt(_0x18b5a5(0x1e4))/0x8*(parseInt(_0x18b5a5(0x1e3))/0x9);if(_0x39ff2f===_0x26c27b)break;else _0x374099['push'](_0x374099['shift']());}catch(_0x222852){_0x374099['push'](_0x374099['shift']());}}}(_0x10c9,0x7ed03));import{eventSource,event_types,main_api,stopGeneration}from'/script.js';import{renderExtensionTemplateAsync}from'/scripts/extensions.js';import{POPUP_RESULT,POPUP_TYPE,Popup}from'/scripts/popup.js';import{t}from'/scripts/i18n.js';import{extensionName}from'../utils/settings.js';const miZheSiPath='third-party/'+extensionName+_0x2b2f8f(0x1f8),STORAGE_KEY=_0x2b2f8f(0x21d);if(!('GENERATE_AFTER_COMBINE_PROMPTS'in event_types)||!(_0x2b2f8f(0x211)in event_types)){toastr['error'](_0x2b2f8f(0x1f2));throw new Error('【密折司】缺少必要的事件支持。');}let inspectEnabled=localStorage['getItem'](STORAGE_KEY)==='true'||![];function addLaunchButton(){const _0xaec32f=_0x2b2f8f,_0x3c7a60=_0xaec32f(0x20b),_0x4dcced='开启Amliy2号密折司',_0x284640=_0xaec32f(0x1dd),_0x18a7d5=()=>inspectEnabled?_0x3c7a60:_0x4dcced,_0xf38b6b=document[_0xaec32f(0x218)](_0xaec32f(0x205));_0xf38b6b['id']=_0xaec32f(0x1ee),_0xf38b6b['classList']['add']('list-group-item',_0xaec32f(0x21c),_0xaec32f(0x1fa),'interactable'),_0xf38b6b[_0xaec32f(0x21e)]=0x0,_0xf38b6b[_0xaec32f(0x20a)]=_0xaec32f(0x204);const _0x35f1a6=document['createElement']('i');_0x35f1a6[_0xaec32f(0x1f6)]=_0x284640,_0xf38b6b[_0xaec32f(0x20e)](_0x35f1a6);const _0x4ec8ef=document[_0xaec32f(0x218)](_0xaec32f(0x213));_0x4ec8ef[_0xaec32f(0x219)]=_0x18a7d5(),_0xf38b6b[_0xaec32f(0x20e)](_0x4ec8ef);const _0x550209=document['getElementById'](_0xaec32f(0x202));if(!_0x550209){console[_0xaec32f(0x1df)](_0xaec32f(0x1e8));return;}if(document[_0xaec32f(0x1e2)](_0xf38b6b['id']))return;_0x550209[_0xaec32f(0x20e)](_0xf38b6b),_0xf38b6b[_0xaec32f(0x1fe)](_0xaec32f(0x1f4),()=>{const _0x5bd3be=_0xaec32f;toggleInspectNext(),_0x4ec8ef[_0x5bd3be(0x219)]=_0x18a7d5(),_0xf38b6b[_0x5bd3be(0x1f7)][_0x5bd3be(0x206)](_0x5bd3be(0x217),inspectEnabled);}),_0xf38b6b[_0xaec32f(0x1f7)][_0xaec32f(0x206)](_0xaec32f(0x217),inspectEnabled);}function toggleInspectNext(){const _0x2406b9=_0x2b2f8f;inspectEnabled=!inspectEnabled,toastr[_0x2406b9(0x1ec)](_0x2406b9(0x20d)+(inspectEnabled?'开启':'关闭')),localStorage['setItem'](STORAGE_KEY,String(inspectEnabled));}async function showPromptInspector(_0x22de4a){const _0x53b144=_0x2b2f8f,_0x44c30d=$(await renderExtensionTemplateAsync(miZheSiPath,_0x53b144(0x1f3))),_0x280d5b=_0x44c30d[_0x53b144(0x1f5)]('#mizhesi-editor-container');let _0x2bd793=![];try{const _0x3ad104=JSON[_0x53b144(0x200)](_0x22de4a);if(Array[_0x53b144(0x1ff)](_0x3ad104))_0x2bd793=!![],_0x280d5b['empty'](),_0x3ad104[_0x53b144(0x1fc)](_0x27b51b=>{const _0x2ef763=_0x53b144,_0x10904e=$(_0x2ef763(0x216)+_0x27b51b[_0x2ef763(0x1e9)]+_0x2ef763(0x209)+_0x27b51b[_0x2ef763(0x1e9)]+_0x2ef763(0x21b));_0x10904e[_0x2ef763(0x1f5)](_0x2ef763(0x1f9))[_0x2ef763(0x1eb)](_0x27b51b[_0x2ef763(0x1f0)]),_0x280d5b[_0x2ef763(0x1fd)](_0x10904e),_0x10904e['find'](_0x2ef763(0x207))['on'](_0x2ef763(0x1f4),function(){const _0x71ba47=_0x2ef763,_0x4ab6e5=$(this)[_0x71ba47(0x226)](_0x71ba47(0x215)),_0x3c0de0=$(this)[_0x71ba47(0x1e5)](_0x71ba47(0x222));_0x3c0de0[_0x71ba47(0x1ed)](_0x71ba47(0x224)),_0x4ab6e5[_0x71ba47(0x20c)](_0x71ba47(0x203));});});else throw new Error(_0x53b144(0x1f1));}catch(_0x20b220){_0x2bd793=![];const _0x2682a8=$('<textarea\x20id=\x22mizhesi-plain-text-editor\x22\x20style=\x22width:\x20100%;\x20height:\x20100%;\x20box-sizing:\x20border-box;\x22></textarea>');_0x2682a8[_0x53b144(0x1eb)](_0x22de4a),_0x280d5b['empty']()[_0x53b144(0x1fd)](_0x2682a8);}const _0x11c384={'text':_0x53b144(0x1db),'result':POPUP_RESULT[_0x53b144(0x227)],'appendAtEnd':!![],'action':async()=>{const _0x5c5039=_0x53b144;await stopGeneration(),await _0x502935[_0x5c5039(0x214)](POPUP_RESULT['CANCELLED']);}},_0x502935=new Popup(_0x44c30d,POPUP_TYPE['CONFIRM'],'',{'wide':!![],'large':!![],'okButton':_0x53b144(0x1ea),'cancelButton':'放弃修改','customButtons':[_0x11c384]}),_0xb4e169=await _0x502935[_0x53b144(0x225)]();if(!_0xb4e169)return _0x22de4a;if(_0x2bd793){const _0x57a43a=[];return _0x44c30d[_0x53b144(0x1f5)]('.mizhesi-message-block')[_0x53b144(0x20f)](function(){const _0x350429=_0x53b144,_0x21036f=$(this)['data'](_0x350429(0x1e9)),_0x50f299=$(this)[_0x350429(0x1f5)]('textarea')[_0x350429(0x1eb)]();_0x57a43a[_0x350429(0x1e1)]({'role':_0x21036f,'content':_0x50f299});}),JSON['stringify'](_0x57a43a,null,0x4);}else return _0x44c30d['find']('#mizhesi-plain-text-editor')[_0x53b144(0x1eb)]();}function _0xe56f(_0x16d288,_0x5c3e15){const _0x10c95b=_0x10c9();return _0xe56f=function(_0xe56f3,_0x39fe1c){_0xe56f3=_0xe56f3-0x1db;let _0x18cb4c=_0x10c95b[_0xe56f3];return _0x18cb4c;},_0xe56f(_0x16d288,_0x5c3e15);}function isChatCompletion(){return main_api==='openai';}eventSource['on'](event_types[_0x2b2f8f(0x1dc)],async _0x5871fa=>{const _0x32b912=_0x2b2f8f;if(!inspectEnabled||_0x5871fa['dryRun']||isChatCompletion())return;if(typeof _0x5871fa[_0x32b912(0x212)]!==_0x32b912(0x1de))return;const _0x26baaa=await showPromptInspector(_0x5871fa['prompt']);_0x26baaa!==_0x5871fa[_0x32b912(0x212)]&&(_0x5871fa[_0x32b912(0x212)]=_0x26baaa,console[_0x32b912(0x1ef)](_0x32b912(0x208)));}),eventSource['on'](event_types[_0x2b2f8f(0x211)],async _0x43794a=>{const _0xc49aa3=_0x2b2f8f;if(!inspectEnabled||_0x43794a['dryRun']||!isChatCompletion())return;if(!Array[_0xc49aa3(0x1ff)](_0x43794a['chat']))return;const _0x525ba0=JSON['stringify'](_0x43794a[_0xc49aa3(0x221)],null,0x4),_0x34315c=await showPromptInspector(_0x525ba0);if(_0x34315c===_0x525ba0)return;try{const _0x4abcbf=JSON[_0xc49aa3(0x200)](_0x34315c);_0x43794a[_0xc49aa3(0x221)][_0xc49aa3(0x1fb)](0x0,_0x43794a[_0xc49aa3(0x221)][_0xc49aa3(0x223)],..._0x4abcbf),console['log']('【密折司】奏章已按御笔修改\x20(Chat\x20Completion)。');}catch(_0x182399){console['error'](_0xc49aa3(0x1e6),_0x182399),toastr['error']('【密折司】解析JSON失败,本次修改未生效。');}}),addLaunchButton(); |