Skip to content

Commit

Permalink
fix: 修复某些情况可能多次添加图标的特性
Browse files Browse the repository at this point in the history
  • Loading branch information
MUKAPP committed Feb 13, 2024
1 parent 2d568e7 commit 1bc2c48
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ function observeElement(selector, callback, callbackEnable = true, interval = 10

// 点击群助手后chat-func-bar会消失,再点群聊才会出现,所以需要再写一个监听
function observeElement2(selector, callback, callbackEnable = true, interval = 100) {
var appeared = false;
try {
const timer = setInterval(function () {
const element = document.querySelector(selector);
if (element) {
if (callbackEnable && !appeared) {
if (callbackEnable) {
callback();
log("已检测到", selector);
appeared = true;
}
} else {
appeared = false;
}
}, interval);
} catch (error) {
Expand Down Expand Up @@ -313,6 +309,11 @@ observeElement('#ml-root .ml-list', function () {
// 获取消息栏的左侧图标区域(就是chat-func-bar的第一个子元素)
const iconBarLeft = document.querySelector(".chat-func-bar").firstElementChild;

// 判断是否已经添加过deepl-bar-icon
if (iconBarLeft.querySelector("#deepl-bar-icon")) {
return;
}

// 复制iconBarLeft的第一个子元素
const barIcon = iconBarLeft.firstElementChild.cloneNode(true);
// 将id-func-bar-expression替换为deepl-bar-icon
Expand Down

0 comments on commit 1bc2c48

Please sign in to comment.