-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.tsx
32 lines (25 loc) · 1.08 KB
/
content.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type { PlasmoCSConfig, PlasmoCSUIJSXContainer, PlasmoRender } from 'plasmo'
import { createRoot } from 'react-dom/client'
import ControlPanel from '~app/components/ControlPanel'
import { ControlPanelRootId } from '~app/constants'
import { getControlPanelParentElement } from '~app/utils/selectors'
export const config: PlasmoCSConfig = {
matches: ['*://news.ycombinator.com/*'],
css: ['content.css']
}
export const getRootContainer = () =>
new Promise((resolve) => {
const checkInterval = setInterval(() => {
const controlPanelParentElement = getControlPanelParentElement()
if (!controlPanelParentElement) return
clearInterval(checkInterval)
const controlPanelRoot = document.createElement('span')
controlPanelRoot.id = ControlPanelRootId
controlPanelParentElement.prepend(controlPanelRoot)
resolve(controlPanelRoot)
}, 155)
})
export const render: PlasmoRender<PlasmoCSUIJSXContainer> = async ({ createRootContainer }) => {
const rootContainer = await createRootContainer()
createRoot(rootContainer).render(<ControlPanel />)
}