Skip to content

Commit

Permalink
Cross-browser templates
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Sep 21, 2024
1 parent 2112210 commit 818ab2e
Show file tree
Hide file tree
Showing 78 changed files with 546 additions and 558 deletions.
12 changes: 1 addition & 11 deletions examples/action/action/scripts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
function getManifest() {
return chrome.runtime.getManifest()
}

const manifestData = getManifest()

console.table({
name: manifestData.name,
version: manifestData.version,
description: manifestData.description
})
console.log('Hello from the browser action page!')
1 change: 0 additions & 1 deletion examples/action/action/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ h1 {
margin-bottom: 1.5rem;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
font-size: 4.7em;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/config-babel/newtab/scripts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function getManifest() {
return chrome.runtime.getManifest()
return browser.runtime.getManifest()
}

const manifestData = getManifest()
Expand Down
1 change: 0 additions & 1 deletion examples/config-babel/newtab/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ h1 {
margin-bottom: 1.5rem;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
font-size: 4.7em;
}
Expand Down
1 change: 0 additions & 1 deletion examples/config-eslint/newtab/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ h1 {
margin-bottom: 1.5rem;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
font-size: 4.7em;
}
Expand Down
1 change: 0 additions & 1 deletion examples/config-lint/newtab/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ h1 {
margin-bottom: 1.5rem;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
font-size: 4.7em;
}
Expand Down
1 change: 0 additions & 1 deletion examples/config-prettier/newtab/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ h1 {
margin-bottom: 1.5rem;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
font-size: 4.7em;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/config-stylelint/newtab/scripts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function getManifest() {
return chrome.runtime.getManifest()
return browser.runtime.getManifest()
}

const manifestData = getManifest()
Expand Down
1 change: 0 additions & 1 deletion examples/config-stylelint/newtab/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ h1 {
margin-bottom: 1.5rem;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
font-size: 4.7em;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/content-css-module/background.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
console.log('hello from background script')

chrome.runtime.onMessage.addListener((request, sender) => {
browser.runtime.onMessage.addListener((request, sender) => {
if (request.action === 'changeBackgroundColor') {
changeBackgroundColor(request.color, sender.tab.id)
}
})

function changeBackgroundColor(color, tabId) {
chrome.scripting
browser.scripting
.executeScript({
target: {tabId},
function: setPageBackgroundColor,
Expand Down
6 changes: 2 additions & 4 deletions examples/content-css-module/content/Logo.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.logo {
width: 90px;
align-self: flex-start;
}

width: 72px;
}
5 changes: 3 additions & 2 deletions examples/content-css-module/content/scripts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import './styles.css'
import styles from './Logo.module.css'
import extensionjsLogo from '../images/extensionjs.svg'

console.log('hello from content_scripts')

document.body.innerHTML += `
<div class="content_script-box">
<img class=${styles.logo} src="/logo.svg" />
<img class=${styles.logo} src="${extensionjsLogo}" />
<h1 class="content_script-title">
Change the background-color ⬇
</h1>
Expand All @@ -23,7 +24,7 @@ document.body.innerHTML += `
`

document.getElementById('colorPicker').addEventListener('input', (event) => {
chrome.runtime
browser.runtime
.sendMessage({
action: 'changeBackgroundColor',
color: event.target.value
Expand Down
26 changes: 12 additions & 14 deletions examples/content-css-module/content/styles.css
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
.content_script-box {
background: white;
color: #c9c9c9;
background-color: #0a0c10;
position: fixed;
right: 0;
bottom: 0;
z-index: 9;
width: 315px;
height: 345px;
margin: 1em;
padding: 1em;
margin: 1rem;
padding: 2rem 1rem;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 1em;
box-shadow: 0px 0px 4px 1px #ccc;
border-radius: 6px;
}

.content_script-title {
font-size: 1.85em;
color: #333;
line-height: 1.1;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
font-weight: 700;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
}

.content_script-description {
color: #999;
font-size: small;
}

.content_script-description a {
text-decoration: none;
border-bottom: 2px solid #c9c9c9;
color: #e5e7eb;
}

.content_script-colorPicker {
display: block;
width: 100%;
height: 50px;
}
3 changes: 3 additions & 0 deletions examples/content-css-module/images/extensionjs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/content-env/background.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
console.log('hello from background script')

// eslint-disable-next-line no-undef
chrome.runtime.onMessage.addListener((request, sender) => {
browser.runtime.onMessage.addListener((request, sender) => {
if (request.action === 'changeBackgroundColor') {
changeBackgroundColor(request.color, sender.tab?.id)
}
Expand All @@ -12,7 +12,7 @@ function changeBackgroundColor(color: string, tabId: number | undefined) {
return
}

chrome.scripting
browser.scripting
.executeScript({
target: {tabId},
func: setContentPageBackgroundColor,

Check failure on line 18 in examples/content-env/background.ts

View workflow job for this annotation

GitHub Actions / build (20)

Type '(color: string) => void' is not assignable to type '() => void | undefined'.
Expand Down
2 changes: 1 addition & 1 deletion examples/content-env/content/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const colorPicker = document.getElementById('colorPicker')
// Add the event listener only if it hasn't been added yet
if (colorPicker && !colorPicker.hasAttribute('data-listener')) {
colorPicker.addEventListener('input', (event) => {
chrome.runtime
browser.runtime
.sendMessage({
action: 'changeBackgroundColor',
// @ts-expect-error
Expand Down
36 changes: 13 additions & 23 deletions examples/content-env/content/styles.css
Original file line number Diff line number Diff line change
@@ -1,52 +1,42 @@
.content_script-box {
background: white;
color: #c9c9c9;
background-color: #0a0c10;
position: fixed;
right: 0;
bottom: 0;
z-index: 9;
width: 315px;
height: 375px;
margin: 1em;
padding: 1em;
margin: 1rem;
padding: 2rem 1rem;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 1em;
box-shadow: 0px 0px 4px 1px #ccc;
}

.content_script-logo-box {
display: flex;
align-items: center;
justify-content: center;
gap: 1em;
border-radius: 6px;
}

.content_script-logo {
width: 90px;
align-self: flex-start;
width: 72px;
}

.content_script-title {
font-size: 1.85em;
color: #333;
line-height: 1.1;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
font-weight: 700;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
}

.content_script-description {
color: #999;
font-size: small;
}

.content_script-description a {
text-decoration: none;
border-bottom: 2px solid #c9c9c9;
color: #e5e7eb;
}

.content_script-colorPicker {
display: block;
width: 100%;
height: 50px;
}
4 changes: 2 additions & 2 deletions examples/content-esm/background.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
console.log('hello from background script')

chrome.runtime.onMessage.addListener((request, sender) => {
browser.runtime.onMessage.addListener((request, sender) => {
if (request.action === 'changeBackgroundColor') {
changeBackgroundColor(request.color, sender.tab.id)
}
})

function changeBackgroundColor(color, tabId) {
chrome.scripting
browser.scripting
.executeScript({
target: {tabId},
function: setPageBackgroundColor,
Expand Down
2 changes: 1 addition & 1 deletion examples/content-esm/content/scripts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ console.log('hello from content_scripts')
document.body.innerHTML += contentComponent

document.getElementById('colorPicker').addEventListener('input', (event) => {
chrome.runtime
browser.runtime
.sendMessage({
action: 'changeBackgroundColor',
color: event.target.value
Expand Down
46 changes: 13 additions & 33 deletions examples/content-esm/content/styles.css
Original file line number Diff line number Diff line change
@@ -1,62 +1,42 @@
.content_script-box {
background: white;
color: #c9c9c9;
background-color: #0a0c10;
position: fixed;
right: 0;
bottom: 0;
z-index: 9;
width: 315px;
height: 345px;
margin: 1em;
padding: 1em;
margin: 1rem;
padding: 2rem 1rem;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 1em;
box-shadow: 0px 0px 4px 1px #ccc;
color: #333;
}

.content_script-header {
display: flex;
align-items: center;
justify-content: left;
gap: 1em;
border-radius: 6px;
}

.content_script-logo {
width: 90px;
align-self: flex-start;
filter: grayscale(1);
transition:
filter 2s,
border-color 2s;
}

.content_script-logo:hover {
filter: grayscale(0);
border-color: aquamarine;
width: 72px;
}

.content_script-title {
font-size: 1.85em;
color: #333;
line-height: 1.1;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
font-weight: 700;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
}

.content_script-description {
color: #999;
font-size: small;
}

.content_script-description a {
text-decoration: none;
border-bottom: 2px solid #c9c9c9;
color: #e5e7eb;
}

.content_script-colorPicker {
display: block;
width: 100%;
height: 50px;
}
4 changes: 2 additions & 2 deletions examples/content-less-module/background.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
console.log('hello from background script')

chrome.runtime.onMessage.addListener((request, sender) => {
browser.runtime.onMessage.addListener((request, sender) => {
if (request.action === 'changeBackgroundColor') {
changeBackgroundColor(request.color, sender.tab.id)
}
})

function changeBackgroundColor(color, tabId) {
chrome.scripting
browser.scripting
.executeScript({
target: {tabId},
function: setPageBackgroundColor,
Expand Down
Loading

0 comments on commit 818ab2e

Please sign in to comment.