diff --git a/README.md b/README.md index 308ad3d8..ab6beab9 100755 --- a/README.md +++ b/README.md @@ -139,6 +139,8 @@ to use it in combination with Tailwind CSS. **Feel free to delete them**. Tailwind can be configured, themed and extended according to the [docs](https://tailwindcss.com/docs/theme). +shadow dom is default enabled for content script. If you want to disable it, you can do it in `src/pages/content/index.tsx` by setting `enableShadowDome` to `false`. + #### Internationalization (i18n) To enable internationalization set the `localize` flag in the `vite.config.base.ts` to `true`. diff --git a/src/pages/content/index.tsx b/src/pages/content/index.tsx index e27a0c73..15f09b21 100644 --- a/src/pages/content/index.tsx +++ b/src/pages/content/index.tsx @@ -1,20 +1,35 @@ -import { createRoot } from 'react-dom/client'; -import './style.css' -const div = document.createElement('div'); -div.id = '__root'; +import { createRoot } from "react-dom/client"; +import './style.css'; + +// disable shadow dom if you want to affect your css styles to current page style +// more on shadow dom: https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM +const enableShadowDome = true; + +const div = document.createElement("div"); +const random = Math.random() * 10000; +div.id = "__root_container_" + random; document.body.appendChild(div); -const rootContainer = document.querySelector('#__root'); +let rootContainer : HTMLElement | ShadowRoot = div; + +if(enableShadowDome) { + const shadow = div.attachShadow({ mode: "open" }); + rootContainer = shadow; + import('./shadowDomStyle').then(({ ImportShadowDomStyle }) => { + ImportShadowDomStyle(shadow); + }); +} + if (!rootContainer) throw new Error("Can't find Content root element"); const root = createRoot(rootContainer); root.render( -
- content script loaded +
+ content script loaded
); try { - console.log('content script loaded'); + console.log("content script loaded"); } catch (e) { console.error(e); } diff --git a/src/pages/content/shadowDomStyle.tsx b/src/pages/content/shadowDomStyle.tsx new file mode 100644 index 00000000..5cdf1357 --- /dev/null +++ b/src/pages/content/shadowDomStyle.tsx @@ -0,0 +1,7 @@ +import cssText from "src/pages/content/style.css?inline"; + +export const ImportShadowDomStyle = (shadow: ShadowRoot) => { + const styleTag = document.createElement("style"); + styleTag.textContent = cssText; + shadow.appendChild(styleTag); +} \ No newline at end of file