Skip to content

Commit

Permalink
chore: improve detect
Browse files Browse the repository at this point in the history
  • Loading branch information
a1mersnow committed Nov 25, 2023
1 parent dff5540 commit df61060
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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
})(),
)
}
}

0 comments on commit df61060

Please sign in to comment.