mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-08 00:55:51 +00:00
Update bindings.js
This commit is contained in:
@@ -6,11 +6,13 @@ import { fetchSupportedModels } from "../core/api.js";
|
|||||||
|
|
||||||
import { setAvailableModels, populateModelDropdown, getLatestUpdateInfo } from "./state.js";
|
import { setAvailableModels, populateModelDropdown, getLatestUpdateInfo } from "./state.js";
|
||||||
import { fixCommand, testReplyChecker } from "../core/commands.js";
|
import { fixCommand, testReplyChecker } from "../core/commands.js";
|
||||||
|
import { createDrawer } from '../ui/drawer.js';
|
||||||
|
import { messageFormatting } from '/script.js';
|
||||||
|
|
||||||
export function bindModalEvents() {
|
export function bindModalEvents() {
|
||||||
const container = $("#amily2_drawer_content");
|
const container = $("#amily2_drawer_content").length ? $("#amily2_drawer_content") : $("#amily2_chat_optimiser");
|
||||||
|
|
||||||
if (container.data("events-bound")) return;
|
if (!container.length || container.data("events-bound")) return;
|
||||||
|
|
||||||
const snakeToCamel = (s) => s.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
const snakeToCamel = (s) => s.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
||||||
const updateAndSaveSetting = (key, value) => {
|
const updateAndSaveSetting = (key, value) => {
|
||||||
@@ -75,7 +77,6 @@ export function bindModalEvents() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
container
|
container
|
||||||
.off("click.amily2.expand_editor")
|
.off("click.amily2.expand_editor")
|
||||||
.on("click.amily2.expand_editor", "#amily2_expand_editor", function (event) {
|
.on("click.amily2.expand_editor", "#amily2_expand_editor", function (event) {
|
||||||
@@ -110,22 +111,24 @@ export function bindModalEvents() {
|
|||||||
.off("click.amily2.update")
|
.off("click.amily2.update")
|
||||||
.on("click.amily2.update", "#amily2_update_button", function() {
|
.on("click.amily2.update", "#amily2_update_button", function() {
|
||||||
$("#amily2_update_indicator").hide();
|
$("#amily2_update_indicator").hide();
|
||||||
|
|
||||||
const updateInfo = getLatestUpdateInfo();
|
const updateInfo = getLatestUpdateInfo();
|
||||||
if (updateInfo && updateInfo.changelog) {
|
if (updateInfo && updateInfo.changelog) {
|
||||||
|
const formattedChangelog = messageFormatting(updateInfo.changelog);
|
||||||
|
|
||||||
|
|
||||||
const dialogHtml = `
|
const dialogHtml = `
|
||||||
<dialog class="popup wide_dialogue_popup">
|
<dialog class="popup wide_dialogue_popup">
|
||||||
<div class="popup-body">
|
<div class="popup-body">
|
||||||
<h3 style="margin-top:0; color: #eee; border-bottom: 1px solid rgba(255,255,255,0.2); padding-bottom: 10px;"><i class="fas fa-bell" style="color: #ff9800;"></i> 帝国最新情报</h3>
|
<h3 style="margin-top:0; color: #eee; border-bottom: 1px solid rgba(255,255,255,0.2); padding-bottom: 10px;"><i class="fas fa-bell" style="color: #ff9800;"></i> 帝国最新情报</h3>
|
||||||
<div class="popup-content" style="height: 60vh; overflow-y: auto; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 5px; white-space: pre-wrap; font-family: 'Consolas', 'Monaco', monospace;">${updateInfo.changelog}</div>
|
<div class="popup-content" style="height: 60vh; overflow-y: auto; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 5px;">
|
||||||
<div class="popup-controls"><div class="popup-button-ok menu_button menu_button_primary interactable">朕已阅</div></div>
|
<div class="mes_text">${formattedChangelog}</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="popup-controls"><div class="popup-button-ok menu_button menu_button_primary interactable">朕已阅</div></div>
|
||||||
</dialog>`;
|
</dialog>`;
|
||||||
const dialogElement = $(dialogHtml).appendTo('body');
|
const dialogElement = $(dialogHtml).appendTo('body');
|
||||||
const closeDialog = () => { dialogElement[0].close(); dialogElement.remove(); };
|
const closeDialog = () => { dialogElement[0].close(); dialogElement.remove(); };
|
||||||
dialogElement.find('.popup-button-ok').on('click', closeDialog);
|
dialogElement.find('.popup-button-ok').on('click', closeDialog);
|
||||||
dialogElement[0].showModal();
|
dialogElement[0].showModal();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
toastr.info("未能获取到云端情报,请稍后再试。", "情报部回报");
|
toastr.info("未能获取到云端情报,请稍后再试。", "情报部回报");
|
||||||
}
|
}
|
||||||
@@ -143,12 +146,11 @@ export function bindModalEvents() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
container
|
container
|
||||||
.off("change.amily2.radio")
|
.off("change.amily2.radio")
|
||||||
.on(
|
.on(
|
||||||
"change.amily2.radio",
|
"change.amily2.radio",
|
||||||
'input[type="radio"][name^="amily2_"]',
|
'input[type="radio"][name^="amily2_"]:not([name="amily2_icon_location"])', // 排除我们的特殊开关
|
||||||
function () {
|
function () {
|
||||||
if (!pluginAuthStatus.authorized) return;
|
if (!pluginAuthStatus.authorized) return;
|
||||||
const key = snakeToCamel(this.name.replace("amily2_", ""));
|
const key = snakeToCamel(this.name.replace("amily2_", ""));
|
||||||
@@ -166,7 +168,6 @@ export function bindModalEvents() {
|
|||||||
toastr.success(`配置 [${key}] 已自动保存!`, "Amily2号");
|
toastr.success(`配置 [${key}] 已自动保存!`, "Amily2号");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
container
|
container
|
||||||
.off("change.amily2.select")
|
.off("change.amily2.select")
|
||||||
.on("change.amily2.select", "select#amily2_model", function () {
|
.on("change.amily2.select", "select#amily2_model", function () {
|
||||||
@@ -176,7 +177,6 @@ export function bindModalEvents() {
|
|||||||
populateModelDropdown();
|
populateModelDropdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
container
|
container
|
||||||
.off("input.amily2.range")
|
.off("input.amily2.range")
|
||||||
.on(
|
.on(
|
||||||
@@ -193,7 +193,6 @@ export function bindModalEvents() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const promptMap = {
|
const promptMap = {
|
||||||
mainPrompt: "#amily2_main_prompt",
|
mainPrompt: "#amily2_main_prompt",
|
||||||
systemPrompt: "#amily2_system_prompt",
|
systemPrompt: "#amily2_system_prompt",
|
||||||
@@ -205,13 +204,13 @@ export function bindModalEvents() {
|
|||||||
const unifiedSaveButton = "#amily2_unified_save_button";
|
const unifiedSaveButton = "#amily2_unified_save_button";
|
||||||
|
|
||||||
function updateEditorView() {
|
function updateEditorView() {
|
||||||
|
if (!$(selector).length) return;
|
||||||
const selectedKey = $(selector).val();
|
const selectedKey = $(selector).val();
|
||||||
if (!selectedKey) return;
|
if (!selectedKey) return;
|
||||||
const content = extension_settings[extensionName][selectedKey] || "";
|
const content = extension_settings[extensionName][selectedKey] || "";
|
||||||
$(editor).val(content);
|
$(editor).val(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
container
|
container
|
||||||
.off("change.amily2.prompt_selector")
|
.off("change.amily2.prompt_selector")
|
||||||
.on("change.amily2.prompt_selector", selector, updateEditorView);
|
.on("change.amily2.prompt_selector", selector, updateEditorView);
|
||||||
@@ -241,3 +240,16 @@ export function bindModalEvents() {
|
|||||||
|
|
||||||
container.data("events-bound", true);
|
container.data("events-bound", true);
|
||||||
}
|
}
|
||||||
|
$(document).on('change', 'input[name="amily2_icon_location"]', function() {
|
||||||
|
if (!pluginAuthStatus.authorized) return;
|
||||||
|
const newLocation = $(this).val();
|
||||||
|
extension_settings[extensionName]['iconLocation'] = newLocation;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
console.log(`[Amily-禁卫军] 收到迁都指令 -> ${newLocation}。圣意已存档。`);
|
||||||
|
toastr.info(`正在将帝国徽记迁往 [${newLocation === 'topbar' ? '顶栏' : '扩展区'}]...`, "迁都令", { timeOut: 2000 });
|
||||||
|
$('#amily2_main_drawer').remove();
|
||||||
|
$(document).off("mousedown.amily2Drawer");
|
||||||
|
$('#amily2_extension_frame').remove();
|
||||||
|
|
||||||
|
setTimeout(createDrawer, 50);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user