Copyfish 开源项目教程
1. 项目的目录结构及介绍
Copyfish 项目的目录结构如下:
Copyfish/
├── css/
│ ├── content.css
│ └── options.css
├── js/
│ ├── background.js
│ ├── content.js
│ ├── options.js
│ └── popup.js
├── images/
│ ├── icon-128.png
│ ├── icon-16.png
│ └── icon-48.png
├── manifest.json
├── options.html
└── popup.html
目录介绍:
- css/: 包含项目的样式文件,如
content.css
和options.css
。 - js/: 包含项目的 JavaScript 文件,如
background.js
,content.js
,options.js
和popup.js
。 - images/: 包含项目的图标文件,如
icon-128.png
,icon-16.png
和icon-48.png
。 - manifest.json: 项目的配置文件,定义了扩展的基本信息和权限。
- options.html: 项目的设置页面。
- popup.html: 项目的弹出页面。
2. 项目的启动文件介绍
Copyfish 项目的启动文件是 manifest.json
。这个文件定义了扩展的基本信息、权限、以及启动时加载的脚本和页面。
manifest.json
示例:
{
"manifest_version": 2,
"name": "Copyfish 🐟 Free OCR Software",
"version": "2.7.0",
"description": "Copy, paste and translate text from any image, video or PDF.",
"icons": {
"16": "images/icon-16.png",
"48": "images/icon-48.png",
"128": "images/icon-128.png"
},
"permissions": [
"activeTab",
"storage",
"contextMenus",
"notifications",
"clipboardWrite",
"clipboardRead"
],
"background": {
"scripts": ["js/background.js"],
"persistent": false
},
"browser_action": {
"default_icon": {
"16": "images/icon-16.png",
"48": "images/icon-48.png",
"128": "images/icon-128.png"
},
"default_popup": "popup.html"
},
"options_ui": {
"page": "options.html",
"open_in_tab": true
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/content.js"],
"css": ["css/content.css"]
}
]
}
启动文件介绍:
manifest_version
: 指定 manifest 文件的版本,通常为 2。name
: 扩展的名称。version
: 扩展的版本号。description
: 扩展的描述。icons
: 扩展的图标。permissions
: 扩展所需的权限。background
: 后台脚本,用于处理后台任务。browser_action
: 浏览器动作,定义了扩展的图标和弹出页面。options_ui
: 设置页面,用户可以在此配置扩展。content_scripts
: 内容脚本,注入到网页中执行的脚本。
3. 项目的配置文件介绍
Copyfish 项目的配置文件是 manifest.json
。这个文件包含了扩展的所有配置信息,如名称、版本、权限、后台脚本、浏览器动作等。
配置文件介绍:
manifest_version
: 指定 manifest 文件的版本。name
: 扩展的名称。version
: 扩展的版本号。description
: 扩展的描述。icons
: 扩展的图标。