Microsoft-Reward-Chrome-Ext 项目教程
1. 项目的目录结构及介绍
Microsoft-Reward-Chrome-Ext/
├── src/
│ ├── background.js
│ ├── content.js
│ ├── options.html
│ ├── options.js
│ ├── popup.html
│ ├── popup.js
│ ├── styles.css
│ └── manifest.json
├── .gitignore
├── LICENSE
├── README.md
├── package.json
└── useragents.json
- src/: 包含项目的所有源代码文件。
- background.js: 后台脚本,处理扩展的主要逻辑。
- content.js: 内容脚本,与网页内容交互。
- options.html: 选项页面,用户可以配置扩展的设置。
- options.js: 选项页面的脚本。
- popup.html: 弹出窗口的HTML文件。
- popup.js: 弹出窗口的脚本。
- styles.css: 样式文件,定义扩展的外观。
- manifest.json: 清单文件,定义扩展的元数据和配置。
- .gitignore: Git忽略文件,指定不需要版本控制的文件和目录。
- LICENSE: 许可证文件,说明项目的许可协议。
- README.md: 项目说明文档。
- package.json: Node.js项目配置文件,包含依赖和脚本。
- useragents.json: 用户代理字符串配置文件。
2. 项目的启动文件介绍
项目的启动文件是 src/manifest.json
,这是一个Chrome扩展的清单文件,它定义了扩展的元数据和配置。以下是该文件的主要内容:
{
"manifest_version": 2,
"name": "Microsoft Rewards Bot",
"version": "1.0",
"description": "A Chrome extension for Microsoft Rewards which automatically clears PC, mobile, and Edge search quests.",
"permissions": [
"activeTab",
"storage",
"tabs",
"https://www.bing.com/*"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
}
},
"options_ui": {
"page": "options.html",
"open_in_tab": true
},
"content_scripts": [
{
"matches": ["https://www.bing.com/*"],
"js": ["content.js"]
}
]
}
- manifest_version: 指定清单文件的版本,当前为2。
- name: 扩展的名称。
- version: 扩展的版本号。
- description: 扩展的描述。
- permissions: 扩展所需的权限。
- background: 后台脚本配置。
- browser_action: 浏览器动作配置,定义弹出窗口和图标。
- options_ui: 选项页面的配置。
- content_scripts: 内容脚本的配置。
3. 项目的配置文件介绍
项目的配置文件主要是 src/manifest.json
和 useragents.json
。
src/manifest.json
如上所述,manifest.json
是Chrome扩展的清单文件,定义了扩展的元数据和配置。
useragents.json
useragents.json
文件包含用户代理字符串的配置,用于模拟不同的设备和浏览器。以下是该文件的示例内容:
{
"pc": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
"mobile": "Mozilla/5.0 (Linux; Android 10; SM-G973U) Apple