BlockAdBlock 项目使用教程
1. 项目的目录结构及介绍
BlockAdBlock 项目的目录结构如下:
BlockAdBlock/
├── LICENSE
├── README.md
├── blockadblock.js
├── bower.json
├── package.json
└── test.html
目录结构介绍
LICENSE
: 项目的许可证文件,采用 MIT 许可证。README.md
: 项目的说明文档,包含项目的基本信息和使用方法。blockadblock.js
: 项目的主要 JavaScript 文件,用于检测广告拦截器。bower.json
: 用于 Bower 包管理器的配置文件。package.json
: 用于 npm 包管理器的配置文件。test.html
: 用于测试广告拦截器检测功能的 HTML 文件。
2. 项目的启动文件介绍
项目的启动文件是 blockadblock.js
。该文件包含了检测广告拦截器的主要逻辑。以下是 blockadblock.js
的基本结构和功能介绍:
// Function called if AdBlock is not detected
function adBlockNotDetected() {
alert('AdBlock is not enabled');
}
// Function called if AdBlock is detected
function adBlockDetected() {
alert('AdBlock is enabled');
}
// Recommended audit because AdBlock lock the file 'blockadblock.js'
// If the file is not called the variable does not exist 'blockAdBlock'
// This means that AdBlock is present
if (typeof blockAdBlock === 'undefined') {
adBlockDetected();
} else {
blockAdBlock.onDetected(adBlockDetected);
blockAdBlock.onNotDetected(adBlockNotDetected);
// and|or
blockAdBlock.on(true, adBlockDetected);
blockAdBlock.on(false, adBlockNotDetected);
// and|or
blockAdBlock.on(true, adBlockDetected).onNotDetected(adBlockNotDetected);
}
启动文件功能介绍
adBlockNotDetected()
: 当广告拦截器未启用时调用的函数。adBlockDetected()
: 当广告拦截器启用时调用的函数。blockAdBlock.onDetected(adBlockDetected)
: 当检测到广告拦截器时调用的函数。blockAdBlock.onNotDetected(adBlockNotDetected)
: 当未检测到广告拦截器时调用的函数。
3. 项目的配置文件介绍
项目的配置文件包括 bower.json
和 package.json
。
bower.json
bower.json
文件用于 Bower 包管理器的配置,包含项目的基本信息和依赖项。
{
"name": "blockadblock",
"version": "3.2.1",
"description": "BlockAdBlock is a JavaScript library to detect AdBlock.",
"main": "blockadblock.js",
"keywords": [
"adblock",
"adblocker",
"blockadblock"
],
"authors": [
"sitexw",
"Valentin",
"master3395",
"Master3395"
],
"license": "MIT",
"homepage": "http://sitexw.fr/blockadblock/",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
package.json
package.json
文件用于 npm 包管理器的配置,包含项目的基本信息和依赖项。
{
"name": "blockadblock",
"version": "3.2.1",
"description": "BlockAdBlock is a JavaScript library to detect AdBlock.",
"main": "blockadblock.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"adblock",
"adblocker",
"blockadblock"
],
"author": "sitexw",
"license": "MIT",
"repository": {
"type": "git