Skip to content

Commit

Permalink
Beta 3
Browse files Browse the repository at this point in the history
  • Loading branch information
sitexw committed Nov 29, 2015
1 parent fec9cc2 commit 47d9c7d
Show file tree
Hide file tree
Showing 7 changed files with 649 additions and 403 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2015 Valentin Allaire <[email protected]>
Copyright (c) 2013-2015 Valentin Allaire <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
140 changes: 102 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Do not use in production!
# Use with caution!

**This Beta is still experimental, and is likely to change significantly!**
**This Beta is still experimental and the bugs may be present.**

*To contribute to this Beta, go here:* https://github.com/sitexw/FuckAdBlock/issues/34

---
---
---

# FuckAdBlock (4.0.0-beta.2)
# FuckAdBlock (4.0.0-beta.3)
Online example: [fuckadblock.sitexw.fr](http://fuckadblock.sitexw.fr)

(A version with a more correct name exists: [BlockAdBlock](https://github.com/sitexw/BlockAdBlock))
Expand All @@ -27,9 +28,9 @@ Download "fuckadblock.min.js" and add it to your site
```
Bower:
```html
bower install fuck-adblock
bower install fuckadblock
```
NodeJS:
NPM:
```html
npm install fuckadblock
```
Expand All @@ -45,15 +46,22 @@ npm install fuckadblock
<script>var fuckAdBlock = undefined;</script>
<script src="./fuckadblock.min.js"></script>
<script>
// We create the function that will be executed if AdBlock is detected
var adBlockDetected = function() {
$('h1 span').text('yes');
}
// We create the function that will be executed if AdBlock is NOT detected
var adBlockUndetected = function() {
$('h1 span').text('no');
}
if(typeof fuckAdBlock === 'undefined') {
// We observe if the variable "fuckAdBlock" exists
if(typeof FuckAdBlock === 'undefined') {
// If it does not exist, it means that AdBlock blocking the script FuckAdBlock
// Therefore the function "adBlockDetected" is executed
// PS: The function is executed on the "document ready" in order to select the HTML with jQuery
$(document).ready(adBlockDetected);
} else {
// Otherwise, our functions we add to FuckAdBlock for a classic detection
fuckAdBlock.on(true, adBlockDetected).on(false, adBlockUndetected);
}
</script>
Expand All @@ -64,7 +72,7 @@ npm install fuckadblock
</html>
```

## Code example (instance and plugin)
## Code example (instance and plugin option)
```html
<!doctype html>
<html>
Expand Down Expand Up @@ -102,16 +110,63 @@ npm install fuckadblock
</html>
```

## Code example (maximum security)
```html
<!doctype html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

<!--
The variables used by FuckAdBlock is initialized
to be sure that another script has not used
-->
<script>var fuckAdBlock = undefined, FuckAdBlock = undefined;</script>
<!--
Added the attribute "integrity" to be sure that the original script
is not modified by an extension or other.
-->
<script src="./fuckadblock.min.js" integrity="sha256-YQPO7mqk9cszSMNteCQ6YaPdRYmlJuR7CG1JP/CUa3s="></script>
<script>
var adBlockDetected = function() {
$('h1 span').text('yes');
}
var adBlockUndetected = function() {
$('h1 span').text('no');
}
if(typeof FuckAdBlock === 'undefined') {
$(document).ready(adBlockDetected);
} else {
fuckAdBlock.on(true, adBlockDetected).on(false, adBlockUndetected);
}
// It removes the variable "fuckadblock" and "FuckAdBlock
// so that it not be exploited by another script later
// but beware, you can not use it too!
fuckAdBlock = undefined;
// Do not use FuckAdBlock outside this area
// (between importing the script and the line above)
</script>
</head>
<body style="font-family: Sans-Serif;">
<h1>AdBlock detected: <span>loading...</span></h1>
</body>
</html>
```
List of SHA256:
- **fuckadblock.js:** `sha256-flllputoHvX4pZ2s1ujIJj3Lu1EuRB5TL+6UKpDEx+o=`
- **fuckadblock.min.js:** `sha256-YQPO7mqk9cszSMNteCQ6YaPdRYmlJuR7CG1JP/CUa3s=`

More information about the attribute "integrity": [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity)

## Code example (other)
```javascript
fuckAdBlock.on(true, adBlockDetected);
fuckAdBlock.on(false, adBlockUndetected);
// or
fuckAdBlock.on(true, adBlockDetected).onNotDetected(adBlockNotDetected);
fuckAdBlock.onDetected(true, adBlockDetected).onNotDetected(adBlockNotDetected);

fuckAdBlock.setOption('timeout', 100);
// or
fuckAdBlock.setOption({
fuckAdBlock.options.set({
timeout: 100,
});
```
Expand All @@ -135,6 +190,9 @@ baitElement: null
baitClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links'
// CSS style used to not see the bait
baitClass: 'width:1px!important;height:1px!important;position:absolute!important;left:-10000px!important;top:-1000px!important;'
// Chose the area (HTML element) which will add the bait
// If null, "window.document.body" used
baitParent: null

// Plugin "http"

Expand All @@ -148,13 +206,12 @@ baitUrl: '/ad/banner/_adsense_/_adserver/_adview_.ad.json?adzone=top&adsize=300x
## Method available
```javascript
// Allows to set options
// @options: string|object
// @value: string (optional)
fuckAdBlock.setOption(options, value);
// @options: object
fuckAdBlock.options.set(options);

// Allows to check if AdBlock is enabled
// @plugins: array (optional, default: all plugins)
// @options: object (optional)
// @options: object (optional, options selected plugins)
fuckAdBlock.check(plugins, options);

// Allows to add an event if AdBlock is detected
Expand All @@ -175,7 +232,6 @@ After that, you are free to create your own instances:
var myFuckAdBlock = new FuckAdBlock;
```


## Plugin
You can create a plugin like this:

Expand All @@ -200,37 +256,39 @@ This plugin detects randomly AdBlock. In this case, there is one chance in five
$(document).ready(adBlockDetected);
} else {
var MyPluginRandom = function() {
this.setOption({
FuckAdBlock.getPluginClass().apply(this, arguments);
this.options.set({
chanceDetected: 0.5,
});
FuckAdBlock.prototype.Plugin.apply(this, arguments);
var data = {};
this.start = function() {
var self = this;
data.myTimeout = setTimeout(function() {
if(Math.random() <= self.options.get('chanceDetected')) {
self.callDetected();
} else {
self.callUndetected();
}
}, 100);
return this;
};
this.stop = function() {
clearTimeout(data.myTimeout);
return this;
};
};
MyPluginRandom.prototype = Object.create(FuckAdBlock.prototype.Plugin.prototype);
MyPluginRandom.prototype.constructor = MyPluginRandom;
MyPluginRandom.prototype.name = 'random';
MyPluginRandom.prototype.start = function() {
var self = this;
this._data.myTimeout = setTimeout(function() {
if(Math.random() <= self.getOption('chanceDetected')) {
self.callDetected();
} else {
self.callUndetected();
}
}, 100);
return this;
};
MyPluginRandom.prototype.stop = function() {
clearTimeout(this._data.myTimeout);
return this;
};
FuckAdBlock.prototype.registerPlugin(MyPluginRandom);
MyPluginRandom.pluginName = 'random';
MyPluginRandom.versionMin = [4, 0, 0];
var myFuckAdBlock = new FuckAdBlock;
myFuckAdBlock.registerPlugin(MyPluginRandom);
myFuckAdBlock.on(true, adBlockDetected).on(false, adBlockUndetected);
$(document).ready(function() {
myFuckAdBlock.check(['random'], {
random: {
chanceDetected: 0.2,
chanceDetected: 0.20,
},
});
});
Expand All @@ -242,3 +300,9 @@ This plugin detects randomly AdBlock. In this case, there is one chance in five
</body>
</html>
```

## Plugin list

Here is a list of plugins (official or not):

*No plugins for now*
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fuck-adblock",
"name": "fuckadblock",
"description": "Detects ad blockers (AdBlock, ...)",
"authors": [{
"name" : "Valentin Allaire",
Expand All @@ -8,6 +8,7 @@
}],
"license": "MIT",
"keywords": [
"fuckadblock",
"adblock",
"advertising",
"ad",
Expand Down
Loading

0 comments on commit 47d9c7d

Please sign in to comment.