mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 11:15:50 +00:00
Update cwb_uiManager.js
This commit is contained in:
@@ -184,7 +184,7 @@ function createCharCardViewerPopupHtml(displayItems) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function bindCharCardViewerPopupEvents($popup) {
|
function bindCharCardViewerPopupEvents($popup) {
|
||||||
$popup.on('change', '.cwb-insertion-position', function () {
|
$popup.on('change', '.cwb-insertion-position', function() {
|
||||||
const $this = $(this);
|
const $this = $(this);
|
||||||
const $depthContainer = $this.closest('.cwb-insertion-settings-content').find('.cwb-insertion-depth-container');
|
const $depthContainer = $this.closest('.cwb-insertion-settings-content').find('.cwb-insertion-depth-container');
|
||||||
if ($this.val() === 'at_depth') {
|
if ($this.val() === 'at_depth') {
|
||||||
@@ -200,7 +200,7 @@ function bindCharCardViewerPopupEvents($popup) {
|
|||||||
showCharCardViewerPopup();
|
showCharCardViewerPopup();
|
||||||
});
|
});
|
||||||
|
|
||||||
$popup.find('#cwb-manual-update-btn').on('click', async function () {
|
$popup.find('#cwb-manual-update-btn').on('click', async function() {
|
||||||
const $button = $(this);
|
const $button = $(this);
|
||||||
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 更新中...');
|
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 更新中...');
|
||||||
await manualUpdateLogic();
|
await manualUpdateLogic();
|
||||||
@@ -217,7 +217,7 @@ function bindCharCardViewerPopupEvents($popup) {
|
|||||||
$popup.find(`#cwb-char-content-${targetUid}`).addClass('active');
|
$popup.find(`#cwb-char-content-${targetUid}`).addClass('active');
|
||||||
});
|
});
|
||||||
|
|
||||||
$popup.find('.cwb-cyber-tab__delete').on('click', async function (e) {
|
$popup.find('.cwb-cyber-tab__delete').on('click', async function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (confirm('您确定要删除这个角色条目吗?此操作不可撤销。')) {
|
if (confirm('您确定要删除这个角色条目吗?此操作不可撤销。')) {
|
||||||
const uidToDelete = $(this).data('char-uid');
|
const uidToDelete = $(this).data('char-uid');
|
||||||
@@ -235,9 +235,9 @@ function bindCharCardViewerPopupEvents($popup) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$popup.find('#cwb-viewer-delete-all').on('click', async function () {
|
$popup.find('#cwb-viewer-delete-all').on('click', async function() {
|
||||||
if (confirm('您确定要清除当前聊天中的所有角色卡和总览吗?此操作将删除所有相关条目,且不可撤销。')) {
|
if (confirm('您确定要清除当前聊天中的所有角色卡和总览吗?此操作将删除所有相关条目,且不可撤销。')) {
|
||||||
const allUids = $popup.find('.cwb-cyber-tab__button').map(function () {
|
const allUids = $popup.find('.cwb-cyber-tab__button').map(function() {
|
||||||
return $(this).data('char-uid');
|
return $(this).data('char-uid');
|
||||||
}).get();
|
}).get();
|
||||||
if (allUids.length > 0) {
|
if (allUids.length > 0) {
|
||||||
@@ -278,18 +278,10 @@ function bindCharCardViewerPopupEvents($popup) {
|
|||||||
if ($field.data('is-array')) {
|
if ($field.data('is-array')) {
|
||||||
value = value.split('\n').map(l => l.trim()).filter(Boolean);
|
value = value.split('\n').map(l => l.trim()).filter(Boolean);
|
||||||
}
|
}
|
||||||
if (path) {
|
if(path){
|
||||||
setNestedValue(collectedData, path, value);
|
setNestedValue(collectedData, path, value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let localTavernHelper = TavernHelper;
|
|
||||||
if (!localTavernHelper) {
|
|
||||||
// TavernHelper 未定义的情况下触发,但是为什么?
|
|
||||||
(localTavernHelper = window.TavernHelper);
|
|
||||||
if (localTavernHelper) {
|
|
||||||
TavernHelper = localTavernHelper;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const finalContentToSave = buildCustomFormat(collectedData);
|
const finalContentToSave = buildCustomFormat(collectedData);
|
||||||
const allEntries = await TavernHelper.getLorebookEntries(book);
|
const allEntries = await TavernHelper.getLorebookEntries(book);
|
||||||
const entryToUpdate = allEntries.find(e => e.uid === targetUid);
|
const entryToUpdate = allEntries.find(e => e.uid === targetUid);
|
||||||
@@ -334,14 +326,7 @@ function bindCharCardViewerPopupEvents($popup) {
|
|||||||
order: finalEntryData.order,
|
order: finalEntryData.order,
|
||||||
hasDepthField: 'depth' in finalEntryData
|
hasDepthField: 'depth' in finalEntryData
|
||||||
});
|
});
|
||||||
localTavernHelper = TavernHelper;
|
|
||||||
if (!localTavernHelper) {
|
|
||||||
// TavernHelper 未定义的情况下触发,但是为什么?
|
|
||||||
(localTavernHelper = window.TavernHelper);
|
|
||||||
if (localTavernHelper) {
|
|
||||||
TavernHelper = localTavernHelper;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await TavernHelper.setLorebookEntries(book, [finalEntryData]);
|
await TavernHelper.setLorebookEntries(book, [finalEntryData]);
|
||||||
showToastr('success', '角色卡已成功保存!');
|
showToastr('success', '角色卡已成功保存!');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -368,14 +353,6 @@ export async function showCharCardViewerPopup() {
|
|||||||
bindCharCardViewerPopupEvents($(`#${CHAR_CARD_VIEWER_POPUP_ID}`));
|
bindCharCardViewerPopupEvents($(`#${CHAR_CARD_VIEWER_POPUP_ID}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let localTavernHelper = TavernHelper;
|
|
||||||
if (!localTavernHelper) {
|
|
||||||
// TavernHelper 未定义的情况下触发,但是为什么?
|
|
||||||
(localTavernHelper = window.TavernHelper);
|
|
||||||
if (localTavernHelper) {
|
|
||||||
TavernHelper = localTavernHelper;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const allEntries = await TavernHelper.getLorebookEntries(book);
|
const allEntries = await TavernHelper.getLorebookEntries(book);
|
||||||
let currentChatId = state.currentChatFileIdentifier;
|
let currentChatId = state.currentChatFileIdentifier;
|
||||||
|
|
||||||
@@ -430,6 +407,7 @@ export async function showCharCardViewerPopup() {
|
|||||||
const characterEntries = relevantEntries
|
const characterEntries = relevantEntries
|
||||||
.filter(entry => !entry.keys.includes('Amily2角色总集'))
|
.filter(entry => !entry.keys.includes('Amily2角色总集'))
|
||||||
.map(entry => {
|
.map(entry => {
|
||||||
|
try {
|
||||||
logDebug(`[DEBUG] 原始条目数据 UID:${entry.uid}`, {
|
logDebug(`[DEBUG] 原始条目数据 UID:${entry.uid}`, {
|
||||||
position: entry.position,
|
position: entry.position,
|
||||||
depth: entry.depth,
|
depth: entry.depth,
|
||||||
@@ -469,8 +447,12 @@ export async function showCharCardViewerPopup() {
|
|||||||
insertionDepth: finalDepth,
|
insertionDepth: finalDepth,
|
||||||
insertionOrder: entry.order ?? 7001,
|
insertionOrder: entry.order ?? 7001,
|
||||||
};
|
};
|
||||||
|
} catch (e) {
|
||||||
|
logError(`解析角色条目失败 (UID: ${entry.uid}),已跳过。`, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.filter(c => c.parsed && Object.keys(c.parsed).length > 0);
|
.filter(c => c && c.parsed && Object.keys(c.parsed).length > 0);
|
||||||
|
|
||||||
displayItems = displayItems.concat(characterEntries);
|
displayItems = displayItems.concat(characterEntries);
|
||||||
|
|
||||||
@@ -641,39 +623,39 @@ export function updateViewerButtonVisibility() {
|
|||||||
export function bindCwbApiEvents() {
|
export function bindCwbApiEvents() {
|
||||||
console.log('[CWB] Binding API events');
|
console.log('[CWB] Binding API events');
|
||||||
|
|
||||||
$('#cwb-api-url').off('input').on('input', function () {
|
$('#cwb-api-url').off('input').on('input', function() {
|
||||||
const value = $(this).val();
|
const value = $(this).val();
|
||||||
extension_settings[extensionName].cwb_api_url = value;
|
extension_settings[extensionName].cwb_api_url = value;
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#cwb-api-key').off('input').on('input', function () {
|
$('#cwb-api-key').off('input').on('input', function() {
|
||||||
const value = $(this).val();
|
const value = $(this).val();
|
||||||
extension_settings[extensionName].cwb_api_key = value;
|
extension_settings[extensionName].cwb_api_key = value;
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#cwb-model').off('input').on('input', function () {
|
$('#cwb-model').off('input').on('input', function() {
|
||||||
const value = $(this).val();
|
const value = $(this).val();
|
||||||
extension_settings[extensionName].cwb_model = value;
|
extension_settings[extensionName].cwb_model = value;
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#cwb-temperature').off('input').on('input', function () {
|
$('#cwb-temperature').off('input').on('input', function() {
|
||||||
const value = parseFloat($(this).val());
|
const value = parseFloat($(this).val());
|
||||||
$('#cwb-temperature-value').text(value);
|
$('#cwb-temperature-value').text(value);
|
||||||
extension_settings[extensionName].cwb_temperature = value;
|
extension_settings[extensionName].cwb_temperature = value;
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#cwb-max-tokens').off('input').on('input', function () {
|
$('#cwb-max-tokens').off('input').on('input', function() {
|
||||||
const value = parseInt($(this).val());
|
const value = parseInt($(this).val());
|
||||||
$('#cwb-max-tokens-value').text(value);
|
$('#cwb-max-tokens-value').text(value);
|
||||||
extension_settings[extensionName].cwb_max_tokens = value;
|
extension_settings[extensionName].cwb_max_tokens = value;
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#cwb-test-connection').off('click').on('click', async function () {
|
$('#cwb-test-connection').off('click').on('click', async function() {
|
||||||
const $button = $(this);
|
const $button = $(this);
|
||||||
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 测试中...');
|
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 测试中...');
|
||||||
|
|
||||||
@@ -686,7 +668,7 @@ export function bindCwbApiEvents() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#cwb-fetch-models').off('click').on('click', async function () {
|
$('#cwb-fetch-models').off('click').on('click', async function() {
|
||||||
const $button = $(this);
|
const $button = $(this);
|
||||||
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 获取中...');
|
$button.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 获取中...');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user