mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 11:15:50 +00:00
Update cwb_settingsManager.js
This commit is contained in:
@@ -209,7 +209,8 @@ export function bindSettingsEvents($settingsPanel) {
|
|||||||
});
|
});
|
||||||
$panel.on('change', '#cwb-api-mode', function() {
|
$panel.on('change', '#cwb-api-mode', function() {
|
||||||
const selectedMode = $(this).val();
|
const selectedMode = $(this).val();
|
||||||
|
|
||||||
|
// 自动保存API模式设置
|
||||||
getSettings().cwb_api_mode = selectedMode;
|
getSettings().cwb_api_mode = selectedMode;
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
|
||||||
@@ -222,7 +223,8 @@ export function bindSettingsEvents($settingsPanel) {
|
|||||||
});
|
});
|
||||||
$panel.on('change', '#cwb-tavern-profile', function() {
|
$panel.on('change', '#cwb-tavern-profile', function() {
|
||||||
const selectedProfile = $(this).val();
|
const selectedProfile = $(this).val();
|
||||||
|
|
||||||
|
// 自动保存SillyTavern预设选择
|
||||||
getSettings().cwb_tavern_profile = selectedProfile;
|
getSettings().cwb_tavern_profile = selectedProfile;
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
|
||||||
@@ -233,24 +235,44 @@ export function bindSettingsEvents($settingsPanel) {
|
|||||||
|
|
||||||
updateApiStatusDisplay($panel);
|
updateApiStatusDisplay($panel);
|
||||||
});
|
});
|
||||||
|
// 添加API字段的实时保存
|
||||||
$panel.on('input', '#cwb-api-url', function() {
|
$panel.on('input', '#cwb-api-url', function() {
|
||||||
const apiUrl = $(this).val().trim();
|
const apiUrl = $(this).val().trim();
|
||||||
|
|
||||||
|
// 同时更新设置和状态
|
||||||
getSettings().cwb_api_url = apiUrl;
|
getSettings().cwb_api_url = apiUrl;
|
||||||
|
state.customApiConfig.url = apiUrl;
|
||||||
|
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
updateApiStatusDisplay($panel);
|
updateApiStatusDisplay($panel);
|
||||||
|
|
||||||
|
console.log('[CWB] API URL已更新 - 设置:', getSettings().cwb_api_url, ', 状态:', state.customApiConfig.url);
|
||||||
});
|
});
|
||||||
|
|
||||||
$panel.on('input', '#cwb-api-key', function() {
|
$panel.on('input', '#cwb-api-key', function() {
|
||||||
const apiKey = $(this).val();
|
const apiKey = $(this).val();
|
||||||
|
|
||||||
|
// 同时更新设置和状态
|
||||||
getSettings().cwb_api_key = apiKey;
|
getSettings().cwb_api_key = apiKey;
|
||||||
|
state.customApiConfig.apiKey = apiKey;
|
||||||
|
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
|
||||||
|
console.log('[CWB] API Key已更新 - 设置长度:', getSettings().cwb_api_key?.length || 0, ', 状态长度:', state.customApiConfig.apiKey?.length || 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
$panel.on('change', '#cwb-api-model', function() {
|
$panel.on('change', '#cwb-api-model', function() {
|
||||||
const model = $(this).val();
|
const model = $(this).val();
|
||||||
|
|
||||||
|
// 同时更新设置和状态
|
||||||
getSettings().cwb_api_model = model;
|
getSettings().cwb_api_model = model;
|
||||||
|
state.customApiConfig.model = model;
|
||||||
|
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
updateApiStatusDisplay($panel);
|
updateApiStatusDisplay($panel);
|
||||||
|
|
||||||
|
console.log('[CWB] 模型已更新 - 设置:', getSettings().cwb_api_model, ', 状态:', state.customApiConfig.model);
|
||||||
|
|
||||||
if (model) {
|
if (model) {
|
||||||
showToastr('success', `模型已选择: ${model}`);
|
showToastr('success', `模型已选择: ${model}`);
|
||||||
}
|
}
|
||||||
@@ -480,10 +502,13 @@ export function loadSettings() {
|
|||||||
console.log('[CWB] Loading settings...');
|
console.log('[CWB] Loading settings...');
|
||||||
|
|
||||||
const settings = getSettings();
|
const settings = getSettings();
|
||||||
|
|
||||||
|
// Initialize settings with defaults if not present
|
||||||
if (!settings) {
|
if (!settings) {
|
||||||
extension_settings[extensionName] = { ...cwbCompleteDefaultSettings };
|
extension_settings[extensionName] = { ...cwbCompleteDefaultSettings };
|
||||||
console.log('[CWB] Initialized default settings');
|
console.log('[CWB] Initialized default settings');
|
||||||
} else {
|
} else {
|
||||||
|
// Ensure all default settings exist
|
||||||
Object.keys(cwbCompleteDefaultSettings).forEach(key => {
|
Object.keys(cwbCompleteDefaultSettings).forEach(key => {
|
||||||
if (settings[key] === undefined || settings[key] === null) {
|
if (settings[key] === undefined || settings[key] === null) {
|
||||||
settings[key] = cwbCompleteDefaultSettings[key];
|
settings[key] = cwbCompleteDefaultSettings[key];
|
||||||
@@ -492,7 +517,8 @@ export function loadSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const finalSettings = getSettings();
|
const finalSettings = getSettings();
|
||||||
|
|
||||||
|
// Apply localStorage overrides
|
||||||
const overrides = JSON.parse(localStorage.getItem(CWB_BOOLEAN_SETTINGS_OVERRIDE_KEY) || '{}');
|
const overrides = JSON.parse(localStorage.getItem(CWB_BOOLEAN_SETTINGS_OVERRIDE_KEY) || '{}');
|
||||||
if (overrides.cwb_master_enabled !== undefined) {
|
if (overrides.cwb_master_enabled !== undefined) {
|
||||||
finalSettings.cwb_master_enabled = overrides.cwb_master_enabled;
|
finalSettings.cwb_master_enabled = overrides.cwb_master_enabled;
|
||||||
@@ -507,6 +533,7 @@ export function loadSettings() {
|
|||||||
finalSettings.cwb_incremental_update_enabled = overrides.cwb_incremental_update_enabled;
|
finalSettings.cwb_incremental_update_enabled = overrides.cwb_incremental_update_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update state object with current settings
|
||||||
state.masterEnabled = finalSettings.cwb_master_enabled;
|
state.masterEnabled = finalSettings.cwb_master_enabled;
|
||||||
state.viewerEnabled = finalSettings.cwb_viewer_enabled;
|
state.viewerEnabled = finalSettings.cwb_viewer_enabled;
|
||||||
state.autoUpdateEnabled = finalSettings.cwb_auto_update_enabled;
|
state.autoUpdateEnabled = finalSettings.cwb_auto_update_enabled;
|
||||||
@@ -530,11 +557,14 @@ export function loadSettings() {
|
|||||||
autoUpdateEnabled: state.autoUpdateEnabled
|
autoUpdateEnabled: state.autoUpdateEnabled
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update UI if panel exists
|
||||||
if ($panel) {
|
if ($panel) {
|
||||||
updateUiWithSettings();
|
updateUiWithSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateControlsLockState();
|
updateControlsLockState();
|
||||||
|
|
||||||
|
// Update viewer button visibility after state is loaded
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const $viewerButton = $(`#${CHAR_CARD_VIEWER_BUTTON_ID}`);
|
const $viewerButton = $(`#${CHAR_CARD_VIEWER_BUTTON_ID}`);
|
||||||
if ($viewerButton.length > 0) {
|
if ($viewerButton.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user