-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add simplified chrome extension setup
- Loading branch information
1 parent
87330d3
commit 0dbf2ff
Showing
15 changed files
with
1,475 additions
and
95 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: ['@repo/eslint-config/react-library.js'], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
'no-unused-vars': [ | ||
2, | ||
{ | ||
argsIgnorePattern: '^_', | ||
varsIgnorePattern: '^_', | ||
caughtErrorsIgnorePattern: '^_', | ||
}, | ||
], | ||
}, | ||
}; |
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,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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,30 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default { | ||
// other rules... | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: ['./tsconfig.json', './tsconfig.node.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
}; | ||
``` | ||
|
||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` | ||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list |
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,3 @@ | ||
chrome.action.onClicked.addListener(tab => { | ||
if (tab.id) chrome.tabs.sendMessage(tab.id, { action: 'togglePane' }); | ||
}); |
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,99 @@ | ||
const createAppFrame = () => { | ||
const className = '__keeep-extension__'; | ||
const styleSheet = new CSSStyleSheet(); | ||
|
||
styleSheet.insertRule(` | ||
.${className} { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
height: 100%; | ||
width: 65%; | ||
max-width: 400px; | ||
max-width: 400px; | ||
box-sizing: border-box; | ||
will-change: transform, opacity; | ||
transition-property: transform, opacity; | ||
z-index: 10000; | ||
background: white; | ||
border: 0; | ||
box-shadow: | ||
0px 0px 1px 0px rgba(24, 26, 27, 0.04), | ||
0px 3px 6px 0px rgba(24, 26, 27, 0.08), | ||
0px 9px 88px 0px rgba(24, 26, 27, 0.28), | ||
0 0 0 1px rgba(141, 141, 141, 0.24); | ||
}`); | ||
|
||
styleSheet.insertRule(` | ||
@media (prefers-reduced-motion: no-preference) { | ||
.${className}[data-visible='true'] { | ||
transition-duration: 400ms; | ||
transition-timing-function: cubic-bezier(0.05, 0.7, 0.1, 1); | ||
} | ||
}`); | ||
|
||
styleSheet.insertRule(` | ||
.${className}[data-visible='true'] { | ||
opacity: 1; | ||
transform: translateX(0); | ||
pointer-events: auto; | ||
} | ||
`); | ||
|
||
styleSheet.insertRule(` | ||
@media (prefers-reduced-motion: no-preference) { | ||
.${className}[data-visible='false'] { | ||
transition-duration: 200ms; | ||
transition-timing-function: cubic-bezier(0.3, 0, 0.8, 0.15); | ||
} | ||
}`); | ||
|
||
styleSheet.insertRule(` | ||
.${className}[data-visible='false'] { | ||
opacity: 0; | ||
transform: translateX(100%); | ||
pointer-events: none; | ||
}`); | ||
|
||
document.adoptedStyleSheets.push(styleSheet); | ||
|
||
const iframe = document.createElement('iframe'); | ||
iframe.src = chrome.runtime.getURL('iframe.html'); | ||
iframe.dataset.visible = 'false'; | ||
iframe.style.display = 'none'; | ||
iframe.className = className; | ||
|
||
return iframe; | ||
}; | ||
|
||
const iframeElement = createAppFrame(); | ||
document.body.appendChild(iframeElement); | ||
|
||
const setPaneVisibility = (element: HTMLElement, isVisible: boolean) => { | ||
if (isVisible) { | ||
element.style.display = ''; | ||
} else { | ||
if (window.matchMedia('(prefers-reduced-motion: no-preference)').matches) { | ||
element.addEventListener( | ||
'transitionend', | ||
() => { | ||
element.style.display = | ||
element.dataset.visible === 'true' ? 'block' : 'none'; | ||
}, | ||
{ once: true } | ||
); | ||
} else { | ||
element.style.display = 'none'; | ||
} | ||
} | ||
|
||
requestAnimationFrame(() => { | ||
element.dataset.visible = isVisible ? 'true' : 'false'; | ||
}); | ||
}; | ||
|
||
chrome.runtime.onMessage.addListener(message => { | ||
if (message.action === 'togglePane') { | ||
setPaneVisibility(iframeElement, iframeElement.dataset.visible === '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,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>keeep Extension</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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,28 @@ | ||
{ | ||
"name": "chrome-extension", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"prettier": "@repo/prettier-config/tailwindcss.js", | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@crxjs/vite-plugin": "beta", | ||
"@repo/eslint-config": "*", | ||
"@types/chrome": "^0.0.266", | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"eslint": "^8.53.0", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.2.0" | ||
} | ||
} |
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,26 @@ | ||
import { useState } from 'react'; | ||
|
||
function App() { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div className="root"> | ||
<h1> | ||
<span>Vitedasddas11</span> | ||
</h1> | ||
<div className="card"> | ||
<button onClick={() => setCount(count => count + 1)}> | ||
count is {count} | ||
</button> | ||
<p> | ||
Edit <code>src/App.tsx</code> and to test HMR | ||
</p> | ||
</div> | ||
<p className="read-the-docs"> | ||
Click on the Vite and React logos to learn more | ||
</p> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
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,9 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); |
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 @@ | ||
/// <reference types="vite/client" /> |
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,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src", "content-script.ts"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"skipLibCheck": true, | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true | ||
}, | ||
"include": ["vite.config.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,34 @@ | ||
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import { crx, defineManifest } from '@crxjs/vite-plugin'; | ||
|
||
const manifest = defineManifest({ | ||
manifest_version: 3, | ||
name: 'keeep Extension', | ||
version: '1.0.0', | ||
action: { | ||
default_title: 'keeep Extension', | ||
default_icon: 'icon.png', | ||
}, | ||
background: { | ||
service_worker: './background.ts', | ||
}, | ||
content_scripts: [ | ||
{ | ||
js: ['./content-inject.ts'], | ||
matches: ['https://www.linkedin.com/*'], | ||
}, | ||
], | ||
web_accessible_resources: [ | ||
{ | ||
resources: ['iframe.html'], | ||
matches: ['https://www.linkedin.com/*'], | ||
}, | ||
], | ||
}); | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react(), crx({ manifest })], | ||
server: { hmr: { clientPort: 5173 } }, | ||
}); |
Oops, something went wrong.