File tree Expand file tree Collapse file tree 13 files changed +87
-76
lines changed
content-extension-config/content
content-main-world/content
content-react-svgr/content
content-typescript/content Expand file tree Collapse file tree 13 files changed +87
-76
lines changed Original file line number Diff line number Diff line change @@ -26,13 +26,15 @@ function initial() {
26
26
// prevents conflicts with the host page's styles.
27
27
// This way, styles from the extension won't leak into the host page.
28
28
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
29
- const style = new CSSStyleSheet ( )
30
- shadowRoot . adoptedStyleSheets = [ style ]
31
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
29
+
30
+
31
+ const styleElement = document . createElement ( 'style' )
32
+ shadowRoot . appendChild ( styleElement )
33
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
32
34
33
35
if ( import . meta. webpackHot ) {
34
36
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
35
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
37
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
36
38
} )
37
39
}
38
40
@@ -46,7 +48,6 @@ function initial() {
46
48
47
49
return ( ) => {
48
50
rootDiv . remove ( )
49
-
50
51
}
51
52
}
52
53
Original file line number Diff line number Diff line change @@ -28,22 +28,24 @@ function initial() {
28
28
// prevents conflicts with the host page's styles.
29
29
// This way, styles from the extension won't leak into the host page.
30
30
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
31
- const style = new CSSStyleSheet ( )
32
- shadowRoot . adoptedStyleSheets = [ style ]
33
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
31
+
32
+ const styleElement = document . createElement ( 'style' )
33
+ shadowRoot . appendChild ( styleElement )
34
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
34
35
35
36
if ( import . meta. webpackHot ) {
36
37
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
37
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
38
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
38
39
} )
39
40
}
40
41
41
- const mountingPoint = ReactDOM . createRoot ( shadowRoot )
42
- mountingPoint . render (
43
- < div className = "content_script" >
44
- < ContentApp />
45
- </ div >
46
- )
42
+ // Create container for React app
43
+ const container = document . createElement ( 'div' )
44
+ container . className = 'content_script'
45
+ shadowRoot . appendChild ( container )
46
+
47
+ const mountingPoint = ReactDOM . createRoot ( container )
48
+ mountingPoint . render ( < ContentApp /> )
47
49
return ( ) => {
48
50
mountingPoint . unmount ( )
49
51
rootDiv . remove ( )
Original file line number Diff line number Diff line change @@ -27,15 +27,18 @@ function initial() {
27
27
// prevents conflicts with the host page's styles.
28
28
// This way, styles from the extension won't leak into the host page.
29
29
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
30
- const style = new CSSStyleSheet ( )
31
- shadowRoot . adoptedStyleSheets = [ style ]
30
+
31
+ const styleElement = document . createElement ( 'style' )
32
+ shadowRoot . appendChild ( styleElement )
32
33
33
34
// Fetch and apply LESS styles
34
- fetchLessStyles ( ) . then ( ( response ) => style . replace ( response ) )
35
+ fetchLessStyles ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
35
36
36
37
if ( import . meta. webpackHot ) {
37
38
import . meta. webpackHot ?. accept ( './styles.less' , ( ) => {
38
- fetchLessStyles ( ) . then ( ( response ) => style . replace ( response ) )
39
+ fetchLessStyles ( ) . then (
40
+ ( response ) => ( styleElement . textContent = response )
41
+ )
39
42
} )
40
43
}
41
44
Original file line number Diff line number Diff line change @@ -25,13 +25,14 @@ function initial() {
25
25
// prevents conflicts with the host page's styles.
26
26
// This way, styles from the extension won't leak into the host page.
27
27
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
28
- const style = new CSSStyleSheet ( )
29
- shadowRoot . adoptedStyleSheets = [ style ]
30
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
28
+
29
+ const styleElement = document . createElement ( 'style' )
30
+ shadowRoot . appendChild ( styleElement )
31
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
31
32
32
33
if ( import . meta. webpackHot ) {
33
34
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
34
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
35
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
35
36
} )
36
37
}
37
38
Original file line number Diff line number Diff line change @@ -28,22 +28,23 @@ function initial() {
28
28
// prevents conflicts with the host page's styles.
29
29
// This way, styles from the extension won't leak into the host page.
30
30
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
31
- const style = new CSSStyleSheet ( )
32
- shadowRoot . adoptedStyleSheets = [ style ]
33
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
31
+
32
+ const styleElement = document . createElement ( 'style' )
33
+ shadowRoot . appendChild ( styleElement )
34
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
34
35
35
36
if ( import . meta. webpackHot ) {
36
37
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
37
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
38
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
38
39
} )
39
40
}
40
41
41
- render (
42
- < div className = "content_script" >
43
- < ContentApp />
44
- </ div > ,
45
- shadowRoot
46
- )
42
+ // Create container for Preact app
43
+ const container = document . createElement ( 'div' )
44
+ container . className = 'content_script'
45
+ shadowRoot . appendChild ( container )
46
+
47
+ render ( < ContentApp /> , container )
47
48
48
49
return ( ) => {
49
50
rootDiv . remove ( )
Original file line number Diff line number Diff line change @@ -28,22 +28,24 @@ function initial() {
28
28
// prevents conflicts with the host page's styles.
29
29
// This way, styles from the extension won't leak into the host page.
30
30
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
31
- const style = new CSSStyleSheet ( )
32
- shadowRoot . adoptedStyleSheets = [ style ]
33
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
31
+
32
+ const styleElement = document . createElement ( 'style' )
33
+ shadowRoot . appendChild ( styleElement )
34
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
34
35
35
36
if ( import . meta. webpackHot ) {
36
37
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
37
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
38
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
38
39
} )
39
40
}
40
41
41
- const mountingPoint = ReactDOM . createRoot ( shadowRoot )
42
- mountingPoint . render (
43
- < div className = "content_script" >
44
- < ContentApp />
45
- </ div >
46
- )
42
+ // Create container for React app
43
+ const container = document . createElement ( 'div' )
44
+ container . className = 'content_script'
45
+ shadowRoot . appendChild ( container )
46
+
47
+ const mountingPoint = ReactDOM . createRoot ( container )
48
+ mountingPoint . render ( < ContentApp /> )
47
49
return ( ) => {
48
50
mountingPoint . unmount ( )
49
51
rootDiv . remove ( )
Original file line number Diff line number Diff line change @@ -28,17 +28,22 @@ function initial() {
28
28
// prevents conflicts with the host page's styles.
29
29
// This way, styles from the extension won't leak into the host page.
30
30
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
31
- const style = new CSSStyleSheet ( )
32
- shadowRoot . adoptedStyleSheets = [ style ]
33
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
31
+
32
+ const styleElement = document . createElement ( 'style' )
33
+ shadowRoot . appendChild ( styleElement )
34
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
34
35
35
36
if ( import . meta. webpackHot ) {
36
37
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
37
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
38
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
38
39
} )
39
40
}
40
41
41
- const mountingPoint = ReactDOM . createRoot ( shadowRoot )
42
+ // Create a container for React to render into
43
+ const container = document . createElement ( 'div' )
44
+ shadowRoot . appendChild ( container )
45
+
46
+ const mountingPoint = ReactDOM . createRoot ( container )
42
47
mountingPoint . render (
43
48
< div className = "content_script" >
44
49
< ContentApp />
Original file line number Diff line number Diff line change @@ -27,11 +27,12 @@ function initial() {
27
27
// prevents conflicts with the host page's styles.
28
28
// This way, styles from the extension won't leak into the host page.
29
29
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
30
- const style = new CSSStyleSheet ( )
31
- shadowRoot . adoptedStyleSheets = [ style ]
30
+
31
+ const styleElement = document . createElement ( 'style' )
32
+ shadowRoot . appendChild ( styleElement )
32
33
33
34
// Fetch and apply CSS styles
34
- fetchCssStyles ( ) . then ( ( response ) => style . replace ( response ) )
35
+ fetchCssStyles ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
35
36
36
37
// Create container div
37
38
const contentDiv = document . createElement ( 'div' )
Original file line number Diff line number Diff line change @@ -27,13 +27,14 @@ function initial() {
27
27
// prevents conflicts with the host page's styles.
28
28
// This way, styles from the extension won't leak into the host page.
29
29
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
30
- const style = new CSSStyleSheet ( )
31
- shadowRoot . adoptedStyleSheets = [ style ]
32
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
30
+
31
+ const styleElement = document . createElement ( 'style' )
32
+ shadowRoot . appendChild ( styleElement )
33
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
33
34
34
35
if ( import . meta. webpackHot ) {
35
36
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
36
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
37
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
37
38
} )
38
39
}
39
40
Original file line number Diff line number Diff line change @@ -26,13 +26,14 @@ function initial() {
26
26
// prevents conflicts with the host page's styles.
27
27
// This way, styles from the extension won't leak into the host page.
28
28
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
29
- const style = new CSSStyleSheet ( )
30
- shadowRoot . adoptedStyleSheets = [ style ]
31
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
29
+
30
+ const styleElement = document . createElement ( 'style' )
31
+ shadowRoot . appendChild ( styleElement )
32
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
32
33
33
34
if ( import . meta. webpackHot ) {
34
35
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
35
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
36
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
36
37
} )
37
38
}
38
39
Original file line number Diff line number Diff line change 1
1
// @ts -expect-error - Import handled by webpack
2
2
import logo from '../images/logo.svg'
3
3
4
- declare global {
5
- interface ImportMeta {
6
- webpackHot ?: {
7
- accept : ( path ?: string , callback ?: ( newModule : any ) => void ) => void
8
- dispose : ( callback : ( ) => void ) => void
9
- }
10
- }
11
- }
12
-
13
4
let unmount : ( ) => void
14
5
15
6
if ( import . meta. webpackHot ) {
Original file line number Diff line number Diff line change @@ -27,13 +27,14 @@ function initial() {
27
27
// prevents conflicts with the host page's styles.
28
28
// This way, styles from the extension won't leak into the host page.
29
29
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
30
- const style = new CSSStyleSheet ( )
31
- shadowRoot . adoptedStyleSheets = [ style ]
32
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
30
+
31
+ const styleElement = document . createElement ( 'style' )
32
+ shadowRoot . appendChild ( styleElement )
33
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
33
34
34
35
if ( import . meta. webpackHot ) {
35
36
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
36
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
37
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
37
38
} )
38
39
}
39
40
Original file line number Diff line number Diff line change @@ -26,13 +26,14 @@ function initial() {
26
26
// prevents conflicts with the host page's styles.
27
27
// This way, styles from the extension won't leak into the host page.
28
28
const shadowRoot = rootDiv . attachShadow ( { mode : 'open' } )
29
- const style = new CSSStyleSheet ( )
30
- shadowRoot . adoptedStyleSheets = [ style ]
31
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
29
+
30
+ const styleElement = document . createElement ( 'style' )
31
+ shadowRoot . appendChild ( styleElement )
32
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
32
33
33
34
if ( import . meta. webpackHot ) {
34
35
import . meta. webpackHot ?. accept ( './styles.css' , ( ) => {
35
- fetchCSS ( ) . then ( ( response ) => style . replace ( response ) )
36
+ fetchCSS ( ) . then ( ( response ) => ( styleElement . textContent = response ) )
36
37
} )
37
38
}
38
39
You can’t perform that action at this time.
0 commit comments