-
Notifications
You must be signed in to change notification settings - Fork 1
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
choukin
committed
Jan 2, 2024
1 parent
720c42d
commit 3e99689
Showing
19 changed files
with
197 additions
and
44 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,10 @@ | ||
# chrome 插件 | ||
|
||
## 插件组成 | ||
|
||
- background scripts 后台脚本 | ||
- content scripts 内容脚本 | ||
- options page 选项页面 | ||
- UI elements UI 元素 | ||
- 各种逻辑文件 | ||
- manifest.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 @@ | ||
let color = '#3aa757'; | ||
|
||
chrome.runtime.onInstalled.addListener(() => { | ||
chrome.storage.sync.set({ color }); | ||
console.log("🚀 ~ file: background.js:5 ~ chrome.runtime.onInstalled.addListener ~ color:", color) | ||
|
||
console.log('Default background color set to %cgreen', `color: ${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,12 @@ | ||
button{ | ||
height:30px; | ||
width:30px; | ||
outline:none; | ||
margin:10px; | ||
border:none; | ||
border-radius:2px; | ||
} | ||
buton.current{ | ||
box-shadow:0 0 0 2px white, | ||
0 0 0 4px black; | ||
} |
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.
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.
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,25 @@ | ||
{ | ||
"name": "Demo1", | ||
"description": "A simple demo cion", | ||
"version": "1.0", | ||
"manifest_version": 3, | ||
"background": { | ||
"service_worker": "background.js" | ||
}, | ||
"permissions": [ | ||
"storage", | ||
"activeTab", | ||
"scripting" | ||
], | ||
"action": { | ||
"default_popup": "popup.html", | ||
"default_icon": { | ||
"32": "icons/32.png" | ||
} | ||
}, | ||
"options_page": "options.html", | ||
"icons": { | ||
"32": "icons/32.png", | ||
"512": "icons/512.png" | ||
} | ||
} |
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,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div id=""buttonDiv""></div> | ||
<div> | ||
<p>选择一个不同的背景颜色</p> | ||
</div> | ||
</body> | ||
<script src="options.js"></script> | ||
</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,14 @@ | ||
let page = document.getElementById('buttonDiv') | ||
let selectedClassName = 'current' | ||
const presetButtonColors = ["#3aa757", "#e8453c", "#f9bb2d", "#4688f1"] | ||
|
||
|
||
function handleButtonClick(event) { | ||
let current = event.target.parentElement.querySelector(`.${selectedClassName}`) | ||
if (current && current !== event.target) { | ||
current.classList.remove(selectedClassName) | ||
} | ||
let color = event.target.dataset.color | ||
event.target.classList.add(selectedClassName); | ||
chrome.storage.sync.set({ 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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="button.css"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<button id="changeColor"></button> | ||
<script src="popup.js"></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,32 @@ | ||
|
||
let changeColor = document.getElementById('changeColor') | ||
|
||
// chrome.storage.sync.get('color', ({ color }) => { | ||
// changeColor.style.backgroundColor = color | ||
|
||
// }) | ||
|
||
|
||
|
||
// let changeColor = document.getElementById('changeColor') | ||
changeColor.addEventListener('click', async () => { | ||
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }) | ||
|
||
chrome.scripting.executeScript({ | ||
target: { tabId: tab.id }, | ||
function: setPageBackgroundColor | ||
}) | ||
}) | ||
|
||
function setPageBackgroundColor() { | ||
chrome.storage.sync.get('color', ({ color }) => { | ||
debugger | ||
document.body.style.backgroundColor = color | ||
}) | ||
} | ||
|
||
|
||
// chrome.storage.sync.get('color', ({ color }) => { | ||
// changeColor.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
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,36 @@ | ||
# nestjs cli | ||
|
||
## 安装 | ||
|
||
```bash | ||
npm install -g @nestjs/cli | ||
``` | ||
|
||
## 创建项目 | ||
|
||
```bash | ||
nest new myapp | ||
``` | ||
|
||
### 项目 src 目录 | ||
|
||
```sh | ||
. | ||
├── app.controller.spec.ts | ||
├── app.controller.ts | ||
├── app.module.ts | ||
├── app.service.ts | ||
└── main.ts | ||
``` | ||
|
||
1、`main.ts` 入口文件主文件,类似 vue 的 main.ts. 通过 NestFactory.create() 方法创建一个应用实例。app.listen(3000) 监听一个端口 | ||
2、`app.controller.ts` 路由文件 | ||
3、`app.service.ts` 服务文件,编写业务逻辑 | ||
4、`app.module.ts` 模块文件 | ||
|
||
## nestjs cli 常用命令 | ||
|
||
```sh | ||
# 查看 nestjs cli 所有命令 | ||
nest --help | ||
``` |