-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiaojiecong
committed
Feb 9, 2023
1 parent
e706934
commit 1ddfbe9
Showing
38 changed files
with
312 additions
and
177 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 @@ | ||
console.log('content script') | ||
console.log('content script') |
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,2 @@ | ||
import './style.css' | ||
console.log('popup') |
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,10 @@ | ||
body{ | ||
width: 200px; | ||
height: 50px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 14px; | ||
font-weight: bold; | ||
background-color: blueviolet; | ||
} |
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,12 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
panel | ||
</body> | ||
</html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
panel | ||
</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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
chrome.devtools.panels.create( | ||
'DevPanel', | ||
null, | ||
'../panel.html', | ||
function (panel) { | ||
|
||
} | ||
'panel.html', | ||
function (panel) {} | ||
) | ||
|
||
chrome.devtools.panels.elements.createSidebarPane( | ||
'Sidebar', | ||
function (sidebar) { | ||
sidebar.setPage('../sidebar.html') | ||
sidebar.setPage('sidebar.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
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,12 +1,12 @@ | ||
function setBgColor() { | ||
document.body.style.backgroundColor = '#ff0'; | ||
document.body.style.backgroundColor = '#f00' | ||
} | ||
|
||
chrome.action.onClicked.addListener((tab) => { | ||
if(!tab.url.includes("chrome://")) { | ||
chrome.action.onClicked.addListener((tab) => { | ||
if (!tab.url?.startsWith('chrome://')) { | ||
chrome.scripting.executeScript({ | ||
target: { tabId: tab.id }, | ||
function: setBgColor | ||
}); | ||
}) | ||
} | ||
}); | ||
}) |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
## Usage | ||
The dist directory will be created after starting the project.Then Open chrome://extensions/ and import the dist directory. | ||
```bash | ||
# development | ||
pnpm dev | ||
|
||
# production | ||
pnpm build | ||
``` |
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,20 @@ | ||
{ | ||
"name": "crx-react-sandbox", | ||
"version": "0.0.1", | ||
"scripts": { | ||
"dev": "vite build --watch --mode development", | ||
"build": "vite build" | ||
}, | ||
"dependencies": { | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^17.0.33", | ||
"@types/react-dom": "^17.0.10", | ||
"@vitejs/plugin-react": "^1.0.7", | ||
"vite": "^3.0.9", | ||
"typescript": "^4.5.4", | ||
"vite-plugin-crx-mv3": "workspace:*" | ||
} | ||
} |
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></title> | ||
</head> | ||
<body> | ||
<div id="app"></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,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./src/sandbox.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,37 @@ | ||
import { useEffect, useRef, useState } from "react" | ||
|
||
function Popup() { | ||
const iframeRef = useRef<HTMLIFrameElement>(null) | ||
const [count, setCount] = useState(""); | ||
|
||
useEffect(() => { | ||
window.addEventListener("message", (event) => { | ||
setCount(event.data) | ||
console.log("EVAL output: " + event.data) | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<div | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
padding: 12, | ||
width: 175 | ||
}}> | ||
<button | ||
onClick={() => { | ||
setCount(count + 1) | ||
iframeRef.current?.contentWindow?.postMessage("10 + 20", "*") | ||
}}> | ||
Trigger iframe eval | ||
</button> | ||
<div style={{marginTop:5}}> | ||
Use eval to execute "10 + 20": {count} | ||
</div> | ||
<iframe src="sandbox.html" ref={iframeRef} style={{ display: "none" }} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Popup |
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,7 @@ | ||
import ReactDOM from 'react-dom' | ||
import Popup from './Popup.tsx' | ||
|
||
ReactDOM.render( | ||
<Popup />, | ||
document.getElementById('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,13 @@ | ||
{ | ||
"name": "crx-react-sandbox", | ||
"description": "A Chrome extension demo.", | ||
"version": "1.0.0", | ||
"icons": {}, | ||
"action": { | ||
"default_popup": "../popup.html" | ||
}, | ||
"sandbox":{ | ||
"pages": ["../sandbox.html"] | ||
}, | ||
"manifest_version": 3 | ||
} |
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,21 @@ | ||
import ReactDOM from 'react-dom' | ||
|
||
window.addEventListener("message", async function (event) { | ||
const source = event.source as { | ||
window: WindowProxy | ||
} | ||
source.window.postMessage(eval(event.data), event.origin) | ||
}) | ||
|
||
|
||
ReactDOM.render( | ||
<div | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
padding: 16 | ||
}}> | ||
HELLO SANDBOX | ||
</div>, | ||
document.getElementById('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,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"allowJs": false, | ||
"skipLibCheck": false, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": false, | ||
"noEmit": true, | ||
"jsx": "react-jsx" | ||
}, | ||
"include": ["src"], | ||
"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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"module": "esnext", | ||
"moduleResolution": "node" | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
6 changes: 5 additions & 1 deletion
6
examples/crx-jquery/vite.config.js → examples/crx-react-sandbox/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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react' | ||
import crx from 'vite-plugin-crx-mv3' | ||
|
||
export default defineConfig(({ mode }) => { | ||
return { | ||
plugins: [ | ||
react(), | ||
crx({ | ||
manifest: './src/manifest.json' | ||
manifest: './src/manifest.json', | ||
}), | ||
], | ||
build: { | ||
emptyOutDir: mode == 'production', | ||
rollupOptions: { | ||
} | ||
}, | ||
} | ||
}) |
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.