-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve .env files handling. Fix #40
- Loading branch information
1 parent
9425756
commit 8edf2f1
Showing
73 changed files
with
979 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
EXTENSION_OPENAI_API_KEY='My API Key' | ||
EXTENSION_PUBLIC_OPENAI_API_KEY='My API Key' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
function getManifest() { | ||
return chrome.runtime.getManifest() | ||
} | ||
|
||
const manifest = getManifest() | ||
|
||
console.table({ | ||
name: manifest.name, | ||
version: manifest.version, | ||
description: manifest.description | ||
}) | ||
console.log('Hello, ESLint!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
function getManifest() { | ||
return chrome.runtime.getManifest() | ||
} | ||
|
||
const manifest = getManifest() | ||
|
||
console.table({ | ||
name: manifest.name, | ||
version: manifest.version, | ||
description: manifest.description | ||
}) | ||
console.log('Linters gonna lint!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
function getManifest() { | ||
return chrome.runtime.getManifest() | ||
} | ||
|
||
const manifest = getManifest() | ||
|
||
console.table({ | ||
name: manifest.name, | ||
version: manifest.version, | ||
description: manifest.description | ||
}) | ||
console.log('Hello, Prettier!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EXTENSION_PUBLIC_DESCRIPTION_TEXT="Chrome Extension example" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EXTENSION_PUBLIC_DESCRIPTION_TEXT="Edge Extension example" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EXTENSION_PUBLIC_DESCRIPTION_TEXT="Firefox Add-on example" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
|
||
# testing | ||
coverage | ||
|
||
# production | ||
dist | ||
|
||
# misc | ||
.DS_Store | ||
|
||
# local env files | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# lock files | ||
yarn.lock | ||
package-lock.json | ||
|
||
# debug files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# extension.js | ||
extension-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
console.log('hello from background script') | ||
|
||
// eslint-disable-next-line no-undef | ||
chrome.runtime.onMessage.addListener((request, sender) => { | ||
if (request.action === 'changeBackgroundColor') { | ||
changeBackgroundColor(request.color, sender.tab?.id) | ||
} | ||
}) | ||
|
||
function changeBackgroundColor(color: string, tabId: number | undefined) { | ||
if (!tabId) { | ||
return | ||
} | ||
|
||
chrome.scripting | ||
.executeScript({ | ||
target: {tabId}, | ||
func: setContentPageBackgroundColor, | ||
args: [color] | ||
}) | ||
.catch(console.error) | ||
} | ||
|
||
function setContentPageBackgroundColor(color: string) { | ||
document.body.style.backgroundColor = color | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import dotenvLogo from '../public/logo.png' | ||
import './styles.css' | ||
|
||
console.log( | ||
'hello from content_scripts', | ||
process.env.EXTENSION_PUBLIC_DESCRIPTION_TEXT | ||
) | ||
|
||
// Check if the content has already been added | ||
if (!document.querySelector('.content_script-box')) { | ||
document.body.innerHTML += ` | ||
<div class="content_script-box"> | ||
<div class="content_script-logo-box"> | ||
<img class="content_script-logo" src=${dotenvLogo} /> | ||
</div> | ||
<p class="content_script-description">${process.env.EXTENSION_PUBLIC_DESCRIPTION_TEXT}</p> | ||
<h1 class="content_script-title"> | ||
Change the background-color ⬇ | ||
</h1> | ||
<input type="color" class="content_script-colorPicker" id="colorPicker"> | ||
<p class="content_script-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> | ||
` | ||
} | ||
|
||
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 | ||
.sendMessage({ | ||
action: 'changeBackgroundColor', | ||
// @ts-expect-error | ||
color: event.target?.value | ||
}) | ||
.catch(console.error) | ||
}) | ||
|
||
// Mark the element to avoid adding the listener again | ||
colorPicker.setAttribute('data-listener', 'true') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.content_script-box { | ||
background: white; | ||
position: fixed; | ||
right: 0; | ||
bottom: 0; | ||
z-index: 9; | ||
width: 315px; | ||
height: 375px; | ||
margin: 1em; | ||
padding: 1em; | ||
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; | ||
} | ||
|
||
.content_script-logo { | ||
width: 90px; | ||
align-self: flex-start; | ||
filter: grayscale(1); | ||
transition: filter 2s; | ||
} | ||
|
||
.content_script-logo:hover { | ||
filter: grayscale(0); | ||
} | ||
|
||
.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; | ||
} | ||
|
||
.content_script-colorPicker { | ||
display: block; | ||
width: 100%; | ||
height: 50px; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"manifest_version": 3, | ||
"version": "0.0.1", | ||
"name": "Content Scripts .env Template", | ||
"description": "$EXTENSION_PUBLIC_DESCRIPTION_TEXT", | ||
"icons": { | ||
"16": "images/extension_16.png", | ||
"48": "images/extension_48.png", | ||
"128": "images/extension_128.png" | ||
}, | ||
"permissions": ["activeTab", "scripting"], | ||
"host_permissions": ["<all_urls>"], | ||
"background": { | ||
"chromium:service_worker": "background.ts", | ||
"firefox:scripts": ["background.ts"] | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["content/scripts.ts"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"private": true, | ||
"name": "content-env", | ||
"description": "An Extension.js example.", | ||
"version": "0.0.1", | ||
"author": { | ||
"name": "Cezar Augusto", | ||
"email": "[email protected]", | ||
"url": "https://cezaraugusto.com" | ||
}, | ||
"devDependencies": { | ||
"typescript": "5.3.3" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import path from 'path' | ||
import {execSync} from 'child_process' | ||
import {extensionFixtures} from '../extension-fixtures' | ||
|
||
const exampleDir = 'examples/content-env' | ||
const pathToExtension = path.join(__dirname, `dist/chrome`) | ||
const test = extensionFixtures(pathToExtension, true) | ||
|
||
test.beforeAll(async () => { | ||
execSync(`pnpm extension build ${exampleDir}`, { | ||
cwd: path.join(__dirname, '..') | ||
}) | ||
}) | ||
|
||
test('should exist an element with the class name content_script-box', async ({ | ||
page | ||
}) => { | ||
await page.goto('https://extension.js.org/') | ||
const div = page.locator('body > div.content_script-box') | ||
await test.expect(div).toBeVisible() | ||
}) | ||
|
||
test('should exist an h1 element with specified content', async ({page}) => { | ||
await page.goto('https://extension.js.org/') | ||
const h1 = page.locator('body > div.content_script-box > h1') | ||
await test.expect(h1).toHaveText('Change the background-color ⬇') | ||
}) | ||
|
||
test('should exist a default color value', async ({page}) => { | ||
await page.goto('https://extension.js.org/') | ||
const h1 = page.locator('body > div.content_script-box > h1') | ||
const color = await page.evaluate( | ||
(locator) => { | ||
return window.getComputedStyle(locator!).getPropertyValue('color') | ||
}, | ||
await h1.elementHandle() | ||
) | ||
await test.expect(color).toEqual('rgb(51, 51, 51)') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"jsx": "react-jsx", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"moduleResolution": "node", | ||
"module": "esnext", | ||
"noEmit": true, | ||
"resolveJsonModule": true, | ||
"strict": true, | ||
"target": "esnext", | ||
"verbatimModuleSyntax": true, | ||
"useDefineForClassFields": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["./"], | ||
"exclude": ["node_modules", "dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.