mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
fix: harden panel entry bootstrap
This commit is contained in:
@@ -27,43 +27,85 @@ export function openPanelController(runtime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function injectOptionsMenuEntry(runtime) {
|
function injectOptionsMenuEntry(runtime) {
|
||||||
if (runtime.document.getElementById("option_st_bme_panel")) {
|
const doc = runtime.document;
|
||||||
|
if (!doc || doc.getElementById("option_st_bme_panel")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const menuItem = doc.createElement("a");
|
||||||
const $menuItem = runtime.$(`
|
menuItem.id = "option_st_bme_panel";
|
||||||
<a id="option_st_bme_panel">
|
menuItem.innerHTML =
|
||||||
<i class="fa-lg fa-solid fa-brain"></i>
|
'<i class="fa-lg fa-solid fa-brain"></i><span>记忆图谱</span>';
|
||||||
<span>记忆图谱</span>
|
menuItem.addEventListener("click", async () => {
|
||||||
</a>
|
|
||||||
`).on("click", async () => {
|
|
||||||
try {
|
try {
|
||||||
await ensurePanelBridgeReady(runtime);
|
await ensurePanelBridgeReady(runtime);
|
||||||
openPanelController(runtime);
|
openPanelController(runtime);
|
||||||
runtime.$("#options").hide();
|
runtime.$?.("#options")?.hide?.();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
runtime.console.error("[ST-BME] 点击菜单打开面板失败:", error);
|
runtime.console.error("[ST-BME] 点击菜单打开面板失败:", error);
|
||||||
globalThis.toastr?.error?.("记忆图谱面板加载失败,请查看控制台报错", "ST-BME");
|
globalThis.toastr?.error?.("记忆图谱面板加载失败,请查看控制台报错", "ST-BME");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const $optionsContent = runtime.$("#options .options-content");
|
const anchor = doc.getElementById("option_toggle_logprobs");
|
||||||
const $anchor = runtime.$("#option_toggle_logprobs");
|
const optionsContent = doc.querySelector("#options .options-content");
|
||||||
|
|
||||||
if ($anchor.length > 0) {
|
if (anchor?.parentNode) {
|
||||||
$anchor.after($menuItem);
|
anchor.parentNode.insertBefore(menuItem, anchor.nextSibling);
|
||||||
return true;
|
return true;
|
||||||
} else if ($optionsContent.length > 0) {
|
}
|
||||||
$optionsContent.append($menuItem);
|
if (optionsContent) {
|
||||||
|
optionsContent.appendChild(menuItem);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function injectFloatingBootstrap(runtime) {
|
||||||
|
const doc = runtime.document;
|
||||||
|
if (!doc) return false;
|
||||||
|
let fab = doc.getElementById("bme-floating-ball");
|
||||||
|
if (!fab) {
|
||||||
|
fab = doc.createElement("div");
|
||||||
|
fab.id = "bme-floating-ball";
|
||||||
|
fab.setAttribute("data-status", "idle");
|
||||||
|
fab.setAttribute("data-bme-bootstrap", "true");
|
||||||
|
fab.innerHTML = `
|
||||||
|
<i class="fa-solid fa-brain bme-fab-icon"></i>
|
||||||
|
<span class="bme-fab-tooltip">BME 记忆图谱</span>
|
||||||
|
`;
|
||||||
|
const mountTarget = doc.body || doc.documentElement;
|
||||||
|
if (!mountTarget) return false;
|
||||||
|
mountTarget.appendChild(fab);
|
||||||
|
}
|
||||||
|
if (fab.dataset.bmeBridgeBound === "true") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
fab.dataset.bmeBridgeBound = "true";
|
||||||
|
fab.addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
await ensurePanelBridgeReady(runtime);
|
||||||
|
openPanelController(runtime);
|
||||||
|
} catch (error) {
|
||||||
|
runtime.console.error("[ST-BME] 点击悬浮球打开面板失败:", error);
|
||||||
|
globalThis.toastr?.error?.("记忆图谱面板加载失败,请查看控制台报错", "ST-BME");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function scheduleOptionsMenuInjection(runtime, attempt = 0) {
|
function scheduleOptionsMenuInjection(runtime, attempt = 0) {
|
||||||
if (injectOptionsMenuEntry(runtime)) {
|
try {
|
||||||
return;
|
injectFloatingBootstrap(runtime);
|
||||||
|
} catch (error) {
|
||||||
|
runtime.console.warn("[ST-BME] 悬浮球入口预注入失败:", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (injectOptionsMenuEntry(runtime)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
runtime.console.warn("[ST-BME] 菜单入口注入失败,稍后重试:", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attempt >= MENU_ENTRY_MAX_ATTEMPTS) {
|
if (attempt >= MENU_ENTRY_MAX_ATTEMPTS) {
|
||||||
|
|||||||
36
ui/panel.js
36
ui/panel.js
@@ -1021,21 +1021,21 @@ function _bindFabToggle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _initFloatingBall() {
|
function _initFloatingBall() {
|
||||||
const existing = document.getElementById("bme-floating-ball");
|
let fab = document.getElementById("bme-floating-ball");
|
||||||
if (existing) {
|
if (!fab) {
|
||||||
_fabEl = existing;
|
fab = document.createElement("div");
|
||||||
ensureFabMountedAtRoot();
|
fab.id = "bme-floating-ball";
|
||||||
syncFabPosition();
|
fab.setAttribute("data-status", "idle");
|
||||||
return;
|
fab.innerHTML = `
|
||||||
|
<i class="fa-solid fa-brain bme-fab-icon"></i>
|
||||||
|
<span class="bme-fab-tooltip">BME 记忆图谱</span>
|
||||||
|
`;
|
||||||
|
} else if (!fab.querySelector(".bme-fab-icon")) {
|
||||||
|
fab.innerHTML = `
|
||||||
|
<i class="fa-solid fa-brain bme-fab-icon"></i>
|
||||||
|
<span class="bme-fab-tooltip">BME 记忆图谱</span>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fab = document.createElement("div");
|
|
||||||
fab.id = "bme-floating-ball";
|
|
||||||
fab.setAttribute("data-status", "idle");
|
|
||||||
fab.innerHTML = `
|
|
||||||
<i class="fa-solid fa-brain bme-fab-icon"></i>
|
|
||||||
<span class="bme-fab-tooltip">BME 记忆图谱</span>
|
|
||||||
`;
|
|
||||||
_fabEl = fab;
|
_fabEl = fab;
|
||||||
ensureFabMountedAtRoot();
|
ensureFabMountedAtRoot();
|
||||||
|
|
||||||
@@ -1047,11 +1047,17 @@ function _initFloatingBall() {
|
|||||||
if (saved) {
|
if (saved) {
|
||||||
fab.dataset.positionMode = "saved";
|
fab.dataset.positionMode = "saved";
|
||||||
applyFabPosition(saved, fab);
|
applyFabPosition(saved, fab);
|
||||||
} else {
|
} else if (!fab.style.left || !fab.style.top) {
|
||||||
fab.dataset.positionMode = "default";
|
fab.dataset.positionMode = "default";
|
||||||
syncFabPosition();
|
syncFabPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fab.dataset.bmeFabBound === "true") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fab.dataset.bmeFabBound = "true";
|
||||||
|
delete fab.dataset.bmeBootstrap;
|
||||||
|
|
||||||
// 拖拽 + 点击逻辑
|
// 拖拽 + 点击逻辑
|
||||||
let isDragging = false;
|
let isDragging = false;
|
||||||
let hasMoved = false;
|
let hasMoved = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user