Skip to content

Instantly share code, notes, and snippets.

@austintackaberry
Created January 2, 2023 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austintackaberry/410e7345808a08569d34072c21727eca to your computer and use it in GitHub Desktop.
Save austintackaberry/410e7345808a08569d34072c21727eca to your computer and use it in GitHub Desktop.
Chakra UI Plasmo Content Script
import { Button, ChakraProvider, Flex } from "@chakra-ui/react";
import createCache from "@emotion/cache";
import { CacheProvider } from "@emotion/react";
import type { PlasmoContentScript } from "plasmo";
import { createRoot } from "react-dom/client";
export const config: PlasmoContentScript = {
matches: ["https://plasmo.com/*"]
}
const selector = "table"
export const getRootContainer = () =>
new Promise((resolve) => {
const checkInterval = setInterval(() => {
const element = document.querySelector(
selector
)?.parentNode
if (element) {
const rootContainer = document.createElement("td")
element.insertBefore(
rootContainer,
document.querySelector(replySubmitRowLastItemSelector)
)
clearInterval(checkInterval)
resolve(rootContainer)
}
}, 137)
})
const PlasmoInline = () => {
return (
<div />
)
}
export const render = async ({ createRootContainer }) => {
const rootContainer = await createRootContainer()
const root = createRoot(rootContainer)
const myCache = createCache({
container: rootContainer,
key: "c"
})
root.render(
<CacheProvider value={myCache}>
<ChakraProvider>
<PlasmoInline />
</ChakraProvider>
</CacheProvider>
)
}
export default PlasmoInline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment