From 542c23da68672af507d8b17b8a5c452b33690cee Mon Sep 17 00:00:00 2001 From: Pionxzh Date: Sat, 7 Sep 2024 16:57:36 +0800 Subject: [PATCH] fix: improve menu injection #251 --- src/main.tsx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index da41550..adde464 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -12,17 +12,18 @@ main() function main() { onloadSafe(() => { - const container = document.createElement('div') - // to overlap on the list section - container.style.zIndex = '20' - render(, container) - const styleEl = document.createElement('style') styleEl.id = 'sentinel-css' document.head.append(styleEl) + const injectionWeakMap = new WeakMap() + sentinel.on('nav', (nav) => { - const chatList = document.querySelector('nav > div.overflow-y-auto, nav > div.overflow-y-hidden') + if (injectionWeakMap.has(nav)) return + injectionWeakMap.set(nav, true) + + const container = getMenuContainer() + const chatList = nav.querySelector(':scope > div.overflow-y-auto, :scope > div.overflow-y-hidden') if (chatList) { chatList.after(container) } @@ -34,9 +35,8 @@ function main() { // Support for share page if (isSharePage()) { - const continueUrl = `${location.href}/continue` - sentinel.on(`a[href="${continueUrl}"]`, (link) => { - link.after(container) + sentinel.on(`div[role="presentation"] > .w-full > div >.flex.w-full`, (target) => { + target.prepend(getMenuContainer()) }) } @@ -76,3 +76,11 @@ function main() { }) }) } + +function getMenuContainer() { + const container = document.createElement('div') + // to overlap on the list section + container.style.zIndex = '20' + render(, container) + return container +}