Skip to content

Commit

Permalink
Update all content-* templates
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Nov 22, 2024
1 parent 39fc8dd commit 3e1a7a9
Show file tree
Hide file tree
Showing 36 changed files with 526 additions and 182 deletions.
52 changes: 36 additions & 16 deletions examples/content-css-modules/content/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,40 @@ import logo from '../images/logo.png'

console.log('hello from content_scripts')

document.body.innerHTML += `
<div class="content_script">
<img class=${styles.content_logo} src="${logo}" />
<h1 class="content_title">
Welcome to your CSS Modules Extension
</h1>
<p class="content_description">
Learn more about creating cross-browser extensions at <a
className="underline hover:no-underline"
href="https://extension.js.org"
target="_blank"
>
https://extension.js.org
</a>
</p>
</div>
setTimeout(initial, 1000)

function initial() {
const rootDiv = document.createElement('div')
rootDiv.id = 'extension-root'
document.body.appendChild(rootDiv)

// Injecting content_scripts inside a shadow dom
// prevents conflicts with the host page's styles.
// This way, styles from the extension won't leak into the host page.
const shadowRoot = rootDiv.attachShadow({mode: 'open'})

if (process.env.EXTENSION_MODE === 'development') {
// @ts-expect-error - Tell Extension.js
// to use the shadow root as the root element
// to inject styles into.
window.__EXTENSION_SHADOW_ROOT__ = shadowRoot
}

shadowRoot.innerHTML = `
<div class="content_script">
<img class=${styles.content_logo} src="${logo}" />
<h1 class="content_title">
Welcome to your CSS Modules Extension
</h1>
<p class="content_description">
Learn more about creating cross-browser extensions at <a
className="underline hover:no-underline"
href="https://extension.js.org"
target="_blank"
>
https://extension.js.org
</a>
</p>
</div>
`
}
3 changes: 3 additions & 0 deletions examples/content-css-modules/content/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
font-weight: 700;
margin: 0;
}

.content_description {
font-size: small;
margin: 0;
}

.content_description a {
text-decoration: none;
border-bottom: 2px solid #c9c9c9;
color: #e5e7eb;
margin: 0;
}
55 changes: 37 additions & 18 deletions examples/content-env/content/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,41 @@ console.log(
process.env.EXTENSION_PUBLIC_DESCRIPTION_TEXT
)

// Check if the content has already been added
document.body.innerHTML += `
<div class="content_script">
<img class="content_logo" src="${logo}" />
<p class="content_description">${process.env.EXTENSION_PUBLIC_DESCRIPTION_TEXT}</p>
<h1 class="content_title">
Welcome to your .env Extension
</h1>
<p class="content_description">
Learn more about creating cross-browser extensions at <a
class="underline hover:no-underline"
href="https://extension.js.org"
target="_blank"
>
https://extension.js.org
</a>
</p>
</div>
setTimeout(initial, 1000)

function initial() {
const rootDiv = document.createElement('div')
rootDiv.id = 'extension-root'
document.body.appendChild(rootDiv)

// Injecting content_scripts inside a shadow dom
// prevents conflicts with the host page's styles.
// This way, styles from the extension won't leak into the host page.
const shadowRoot = rootDiv.attachShadow({mode: 'open'})

if (process.env.EXTENSION_MODE === 'development') {
// @ts-expect-error - Tell Extension.js
// to use the shadow root as the root element
// to inject styles into.
window.__EXTENSION_SHADOW_ROOT__ = shadowRoot
}

shadowRoot.innerHTML = `
<div class="content_script">
<img class="content_logo" src="${logo}" />
<p class="content_description">${process.env.EXTENSION_PUBLIC_DESCRIPTION_TEXT}</p>
<h1 class="content_title">
Welcome to your .env Extension
</h1>
<p class="content_description">
Learn more about creating cross-browser extensions at <a
class="underline hover:no-underline"
href="https://extension.js.org"
target="_blank"
>
https://extension.js.org
</a>
</p>
</div>
`
}
3 changes: 3 additions & 0 deletions examples/content-env/content/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
font-weight: 700;
margin: 0;
}

.content_description {
font-size: small;
margin: 0;
}

.content_description a {
text-decoration: none;
border-bottom: 2px solid #c9c9c9;
color: #e5e7eb;
margin: 0;
}
22 changes: 21 additions & 1 deletion examples/content-esm/content/scripts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@ import './styles.css'

console.log('hello from content_scripts')

document.body.innerHTML += contentComponent
setTimeout(initial, 1000)

function initial() {
const rootDiv = document.createElement('div')
rootDiv.id = 'extension-root'
document.body.appendChild(rootDiv)

// Injecting content_scripts inside a shadow dom
// prevents conflicts with the host page's styles.
// This way, styles from the extension won't leak into the host page.
const shadowRoot = rootDiv.attachShadow({mode: 'open'})

if (process.env.EXTENSION_MODE === 'development') {
// @ts-expect-error - Tell Extension.js
// to use the shadow root as the root element
// to inject styles into.
window.__EXTENSION_SHADOW_ROOT__ = shadowRoot
}

shadowRoot.innerHTML = contentComponent
}
3 changes: 3 additions & 0 deletions examples/content-esm/content/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
font-weight: 700;
margin: 0;
}

.content_description {
font-size: small;
margin: 0;
}

.content_description a {
text-decoration: none;
border-bottom: 2px solid #c9c9c9;
color: #e5e7eb;
margin: 0;
}
29 changes: 25 additions & 4 deletions examples/content-extension-config/content/scripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,29 @@ function initial() {
rootDiv.id = 'extension-root'
document.body.appendChild(rootDiv)

// Use `createRoot` to create a root, then render the <App /> component
// Note that `createRoot` takes the container DOM node, not the React element
const root = ReactDOM.createRoot(rootDiv)
root.render(<ContentApp />)
// Injecting content_scripts inside a shadow dom
// prevents conflicts with the host page's styles.
// This way, styles from the extension won't leak into the host page.
const shadowRoot = rootDiv.attachShadow({mode: 'open'})

if (process.env.EXTENSION_MODE === 'development') {
// to use the shadow root as the root element
// to inject styles into.
window.__EXTENSION_SHADOW_ROOT__ = shadowRoot
}

const shadowStyle = document.createElement('style')
shadowStyle.textContent = `
:host {
all: initial; /* Reset all styles */
}
`
shadowRoot.appendChild(shadowStyle)

const root = ReactDOM.createRoot(shadowRoot)
root.render(
<div className="content_script">
<ContentApp />
</div>
)
}
2 changes: 1 addition & 1 deletion examples/content-extension-config/content/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@tailwind components;
@tailwind utilities;

#extension-root {
.content_script {
position: fixed;
bottom: 0;
right: 0;
Expand Down
4 changes: 3 additions & 1 deletion examples/content-extension-config/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
},
"content_scripts": [
{
"matches": ["https://extension.js.org/*"],
"matches": [
"<all_urls>"
],
"js": ["./content/scripts.tsx"]
}
],
Expand Down
54 changes: 37 additions & 17 deletions examples/content-less-modules/content/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,40 @@ import logo from '../images/logo.svg'

console.log('hello from content_scripts')

document.body.innerHTML += `
<div class="content_script">
<img class="${styles.logo}" src="${logo}" />
<h1 class="content_title">
Welcome to your LESS Modules Extension
</h1>
<p class="content_description">
Learn more about creating cross-browser extensions at <a
className="underline hover:no-underline"
href="https://extension.js.org"
target="_blank"
>
https://extension.js.org
</a>
</p>
</div>
`
setTimeout(initial, 1000)

function initial() {
const rootDiv = document.createElement('div')
rootDiv.id = 'extension-root'
document.body.appendChild(rootDiv)

// Injecting content_scripts inside a shadow dom
// prevents conflicts with the host page's styles.
// This way, styles from the extension won't leak into the host page.
const shadowRoot = rootDiv.attachShadow({mode: 'open'})

if (process.env.EXTENSION_MODE === 'development') {
// @ts-expect-error - Tell Extension.js
// to use the shadow root as the root element
// to inject styles into.
window.__EXTENSION_SHADOW_ROOT__ = shadowRoot
}

shadowRoot.innerHTML = `
<div class="content_script">
<img class="${styles.logo}" src="${logo}" />
<h1 class="content_title">
Welcome to your LESS Modules Extension
</h1>
<p class="content_description">
Learn more about creating cross-browser extensions at <a
className="underline hover:no-underline"
href="https://extension.js.org"
target="_blank"
>
https://extension.js.org
</a>
</p>
</div>
`
}
3 changes: 3 additions & 0 deletions examples/content-less-modules/content/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
font-weight: 700;
margin: 0;
}

.content_description {
font-size: small;
margin: 0;
}

.content_description a {
text-decoration: none;
border-bottom: 2px solid #c9c9c9;
color: #e5e7eb;
margin: 0;
}
54 changes: 37 additions & 17 deletions examples/content-less/content/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,40 @@ import logo from '../images/logo.svg'

console.log('hello from content_scripts')

document.body.innerHTML += `
<div class="content_script">
<img class="content_logo" src="${logo}" />
<h1 class="content_title">
Welcome to your LESS Extension
</h1>
<p class="content_description">
Learn more about creating cross-browser extensions at <a
className="underline hover:no-underline"
href="https://extension.js.org"
target="_blank"
>
https://extension.js.org
</a>
</p>
</div>
`
setTimeout(initial, 1000)

function initial() {
const rootDiv = document.createElement('div')
rootDiv.id = 'extension-root'
document.body.appendChild(rootDiv)

// Injecting content_scripts inside a shadow dom
// prevents conflicts with the host page's styles.
// This way, styles from the extension won't leak into the host page.
const shadowRoot = rootDiv.attachShadow({mode: 'open'})

if (process.env.EXTENSION_MODE === 'development') {
// @ts-expect-error - Tell Extension.js
// to use the shadow root as the root element
// to inject styles into.
window.__EXTENSION_SHADOW_ROOT__ = shadowRoot
}

shadowRoot.innerHTML = `
<div class="content_script">
<img class="content_logo" src="${logo}" />
<h1 class="content_title">
Welcome to your LESS Extension
</h1>
<p class="content_description">
Learn more about creating cross-browser extensions at <a
className="underline hover:no-underline"
href="https://extension.js.org"
target="_blank"
>
https://extension.js.org
</a>
</p>
</div>
`
}
Loading

0 comments on commit 3e1a7a9

Please sign in to comment.