From df610602b94f447115ac8cd5ed4fff0783da3847 Mon Sep 17 00:00:00 2001 From: a1mer Date: Sat, 25 Nov 2023 14:15:40 +0800 Subject: [PATCH] chore: improve detect --- src/main.ts | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/main.ts b/src/main.ts index 7af7716..21c5dfc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,36 +1,29 @@ +import type { App } from 'vue' import { createApp } from 'vue' -import App from './App.vue' +import AppRoot from './App.vue' import '@unocss/reset/tailwind.css' import './styles/main.css' import 'uno.css' -let timer: number -Promise.race([ - new Promise((resolve) => { - timer = window.setInterval(() => { - const found = document.querySelector('[class^="nav-tab-content--"]') - if (found) - resolve(true) - }, 100) - }), - new Promise((resolve) => { - setTimeout(() => { - resolve(true) - }, 10000) - }), -]).then(() => { - init() -}) +const ENTRY_ID = 'aliyundrive_rename_a1mersnow' -function init() { - clearInterval(timer) - const app = createApp(App) - app.mount( - (() => { - const app = document.createElement('div') - document.elementFromPoint(0, 0)?.append(app) - return app - })(), - ) +window.setInterval(() => { + const found = document.querySelector('[class^="nav-tab-content--"]') + if (found) + init(found) +}, 300) + +function init(parentEl: Element) { + if (!parentEl.querySelector(`#${ENTRY_ID}`)) { + const app = createApp(AppRoot) + app.mount( + (() => { + const app = document.createElement('div') + app.setAttribute('id', ENTRY_ID) + parentEl.append(app) + return app + })(), + ) + } }