开源项目教程:tosdr/browser-extensions
1. 项目的目录结构及介绍
tosdr/browser-extensions/
├── _locales/
│ ├── en/
│ │ └── messages.json
│ └── fr/
│ └── messages.json
├── assets/
│ ├── icons/
│ └── images/
├── src/
│ ├── background/
│ ├── content/
│ ├── popup/
│ └── options/
├── .gitignore
├── LICENSE
├── README.md
├── manifest.json
└── package.json
_locales/
: 包含不同语言的本地化文件。assets/
: 存放项目的静态资源,如图标和图片。src/
: 项目的源代码目录,包含背景脚本、内容脚本、弹出窗口和选项页面。.gitignore
: Git忽略文件列表。LICENSE
: 项目的许可证文件。README.md
: 项目说明文档。manifest.json
: 浏览器扩展的配置文件。package.json
: Node.js项目的配置文件。
2. 项目的启动文件介绍
项目的启动文件主要是 manifest.json
,它定义了浏览器扩展的基本信息和启动配置。以下是 manifest.json
的主要内容:
{
"manifest_version": 2,
"name": "Terms of Service; Didn't Read",
"version": "1.0",
"description": "I have read and agree to the Terms is the biggest lie on the web. We aim to fix that.",
"icons": {
"16": "assets/icons/icon16.png",
"48": "assets/icons/icon48.png",
"128": "assets/icons/icon128.png"
},
"background": {
"scripts": ["src/background/background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["src/content/content.js"]
}
],
"browser_action": {
"default_popup": "src/popup/popup.html",
"default_icon": {
"16": "assets/icons/icon16.png",
"48": "assets/icons/icon48.png",
"128": "assets/icons/icon128.png"
}
},
"options_ui": {
"page": "src/options/options.html",
"open_in_tab": true
},
"permissions": [
"activeTab",
"storage"
]
}
manifest_version
: 指定清单文件的版本。name
: 扩展的名称。version
: 扩展的版本号。description
: 扩展的描述。icons
: 扩展的图标。background
: 背景脚本的配置。content_scripts
: 内容脚本的配置。browser_action
: 浏览器动作的配置,包括弹出窗口。options_ui
: 选项页面的配置。permissions
: 扩展所需的权限。
3. 项目的配置文件介绍
项目的配置文件主要是 package.json
,它定义了Node.js项目的依赖和脚本。以下是 package.json
的主要内容:
{
"name": "tosdr-browser-extensions",
"version": "1.0.0",
"description": "Browser extensions for Terms of Service; Didn't Read",
"main": "index.js",
"scripts": {
"build": "webpack",
"watch": "webpack --watch",
"test": "jest"
},
"author": "TOSDR",
"license": "AGPL-3.0",
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"babel-loader": "^8.2.2",
"webpack": "^5.