@aiyiran/myclaw 1.1.138 → 1.1.139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/myclaw-inject.js +36 -23
- package/package.json +1 -1
package/assets/myclaw-inject.js
CHANGED
|
@@ -881,39 +881,52 @@ btn.addEventListener("click", function () {
|
|
|
881
881
|
});
|
|
882
882
|
}
|
|
883
883
|
|
|
884
|
+
function hideNativeNewSessionBtn(nativeBtn) {
|
|
885
|
+
nativeBtn.style.setProperty("display", "none", "important");
|
|
886
|
+
}
|
|
887
|
+
|
|
884
888
|
function createNewSessionButton() {
|
|
885
|
-
|
|
889
|
+
var nativeBtn = findNativeNewSessionBtn();
|
|
890
|
+
if (!nativeBtn) {
|
|
891
|
+
setTimeout(createNewSessionButton, 500);
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
886
894
|
|
|
887
|
-
|
|
895
|
+
// 已经替换过,不重复插入
|
|
896
|
+
if (nativeBtn.parentNode && nativeBtn.parentNode.querySelector("#myclaw-newsession-btn")) return;
|
|
897
|
+
|
|
898
|
+
// 隐藏原生按钮
|
|
899
|
+
hideNativeNewSessionBtn(nativeBtn);
|
|
900
|
+
|
|
901
|
+
// 复用原生按钮的 class + innerHTML,外观完全一致
|
|
902
|
+
var btn = document.createElement("button");
|
|
888
903
|
btn.id = "myclaw-newsession-btn";
|
|
889
|
-
btn.
|
|
890
|
-
|
|
891
|
-
"bottom: 8px",
|
|
892
|
-
"right: 335px",
|
|
893
|
-
"padding: 3px 10px",
|
|
894
|
-
"background: rgba(139, 92, 246, 0.85)",
|
|
895
|
-
"color: #fff",
|
|
896
|
-
"font-size: 11px",
|
|
897
|
-
"font-weight: bold",
|
|
898
|
-
"font-family: monospace",
|
|
899
|
-
"border-radius: 4px",
|
|
900
|
-
"z-index: 99999",
|
|
901
|
-
"user-select: none",
|
|
902
|
-
"cursor: pointer",
|
|
903
|
-
"transition: all 0.2s",
|
|
904
|
-
"letter-spacing: 0.5px",
|
|
905
|
-
].join(";");
|
|
906
|
-
btn.textContent = "🆕 新会话";
|
|
904
|
+
btn.className = nativeBtn.className;
|
|
905
|
+
btn.innerHTML = nativeBtn.innerHTML;
|
|
907
906
|
btn.title = "创建新会话(可中文命名)";
|
|
908
907
|
|
|
909
|
-
btn.onmouseenter = function () { btn.style.background = "rgba(124, 58, 237, 1)"; btn.style.transform = "scale(1.05)"; };
|
|
910
|
-
btn.onmouseleave = function () { btn.style.background = "rgba(139, 92, 246, 0.85)"; btn.style.transform = "scale(1)"; };
|
|
911
908
|
btn.onclick = function (e) {
|
|
912
909
|
e.stopPropagation();
|
|
910
|
+
e.preventDefault();
|
|
913
911
|
if (newSessionOpen) { closeNewSessionModal(); } else { openNewSessionModal(); }
|
|
914
912
|
};
|
|
915
913
|
|
|
916
|
-
|
|
914
|
+
nativeBtn.parentNode.insertBefore(btn, nativeBtn);
|
|
915
|
+
|
|
916
|
+
// 监听 shadow DOM 变化:防止 Lit 重渲染后原生按钮恢复显示或我们的按钮被移除
|
|
917
|
+
var shadowRoot = nativeBtn.getRootNode();
|
|
918
|
+
if (shadowRoot && shadowRoot !== document) {
|
|
919
|
+
new MutationObserver(function () {
|
|
920
|
+
var ourBtn = shadowRoot.querySelector("#myclaw-newsession-btn");
|
|
921
|
+
if (!ourBtn) {
|
|
922
|
+
// 被重渲染移除了,重新插入
|
|
923
|
+
createNewSessionButton();
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
var native = shadowRoot.querySelector(".sidebar-new-session:not(#myclaw-newsession-btn)");
|
|
927
|
+
if (native) hideNativeNewSessionBtn(native);
|
|
928
|
+
}).observe(shadowRoot, { childList: true, subtree: true });
|
|
929
|
+
}
|
|
917
930
|
}
|
|
918
931
|
|
|
919
932
|
function closeNewSessionModal() {
|