diff --git a/manifest.json b/manifest.json index 8d6f015..850e27c 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "二维码解析", "slug": "qr_code", "description": "对聊天消息中的二维码进行解析", - "version": "1.3.6", + "version": "1.3.7", "icon": "./icon.png", "authors": [ { @@ -16,7 +16,7 @@ "repo": "xh321/LiteLoaderQQNT-QR-Decode", "branch": "master", "release": { - "tag": "1.3.6" + "tag": "1.3.7" } }, "platform": ["win32", "darwin", "linux"], diff --git a/src/qContextMenu.js b/src/qContextMenu.js index 809f65d..5de33b0 100644 --- a/src/qContextMenu.js +++ b/src/qContextMenu.js @@ -10,62 +10,64 @@ import { decodeQRUrl } from "./decodeQR.js"; * @param {Function} callback 回调函数 */ function addQContextMenu(qContextMenu, icon, title, callback) { - const tempEl = document.createElement("div"); - tempEl.innerHTML = document - .querySelector(`.q-context-menu :not([disabled="true"])`) - .outerHTML.replace(//g, ""); - const item = tempEl.firstChild; - item.id = "web-search"; - if (item.querySelector(".q-icon")) { - item.querySelector(".q-icon").innerHTML = icon; - } - if (item.classList.contains("q-context-menu-item__text")) { - item.innerText = title; - } else { - item.querySelector(".q-context-menu-item__text").innerText = title; - } - item.addEventListener("click", () => { - callback(); - qContextMenu.remove(); - }); - qContextMenu.appendChild(item); + if (qContextMenu.querySelector("#qr-decode-menu") != null) return; + + const tempEl = document.createElement("div"); + tempEl.innerHTML = document + .querySelector(`.q-context-menu :not([disabled="true"])`) + .outerHTML.replace(//g, ""); + const item = tempEl.firstChild; + item.id = "qr-decode-menu"; + if (item.querySelector(".q-icon")) { + item.querySelector(".q-icon").innerHTML = icon; + } + if (item.classList.contains("q-context-menu-item__text")) { + item.innerText = title; + } else { + item.querySelector(".q-context-menu-item__text").innerText = title; + } + item.addEventListener("click", () => { + callback(); + qContextMenu.remove(); + }); + qContextMenu.appendChild(item); } /** * 右键菜单监听 */ function addMainQContextMenu() { - let isRightClick = false; - let imagePath = ""; - let imgEl = null; - document.addEventListener("mouseup", (event) => { - if (event.button === 2) { - isRightClick = true; - imgEl = event.target; - if ( - imgEl.classList.contains("image-content") && - imgEl?.src?.startsWith("appimg://") - ) { - imagePath = imgEl?.src?.replace("appimg://", ""); - } else { - imgEl = null; - imagePath = ""; - } - } else { - isRightClick = false; - imagePath = ""; - } - }); - new MutationObserver(() => { - // log(document.querySelector(".q-context-menu").innerHTML); + let isRightClick = false; + let imagePath = ""; + let imgEl = null; + document.addEventListener("mouseup", (event) => { + if (event.button === 2) { + isRightClick = true; + imgEl = event.target; + if ( + imgEl.classList.contains("image-content") && + imgEl?.src?.startsWith("appimg://") + ) { + imagePath = imgEl?.src?.replace("appimg://", ""); + } else { + imgEl = null; + imagePath = ""; + } + } else { + isRightClick = false; + imagePath = ""; + } + }); + new MutationObserver(() => { + // log(document.querySelector(".q-context-menu").innerHTML); - const qContextMenu = document.querySelector(".q-context-menu"); + const qContextMenu = document.querySelector(".q-context-menu"); - if (qContextMenu && imagePath) { - let localPath = decodeURIComponent(imagePath); - addQContextMenu( - qContextMenu, - ` + if (qContextMenu && imagePath) { + let localPath = decodeURIComponent(imagePath); + addQContextMenu( + qContextMenu, + `