Skip to content

Commit

Permalink
Merge pull request #15 from sitexw/v3.x
Browse files Browse the repository at this point in the history
Merge branch 'v3.x' into 'master'
  • Loading branch information
sitexw committed Apr 17, 2015
2 parents 2ca6c79 + 733cd1e commit 35378d1
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 87 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 FuckAdBlock
Copyright (c) 2015 FuckAdBlock

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
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
FuckAdBlock (v3.0.3)
FuckAdBlock (v3.1.0)
===========

Allows you to detect those nasty ad blockers.
You can detect nasty ad blockers.
Online example: http://sitexw.fr/fuckadblock/


Valid on :
Valid on
---------------------
- Google Chrome
- Mozilla Firefox
- Internet Explorer (8+)
- Safari
- Opera

Install via
---------------------
Manual:
```
Download "fuckadblock.js" and add it to your website.
```
Bower:
```
bower install fuck-adblock
```
Node.js/io.js:
```
npm install fuckadblock
```


Code example
---------------------
```javascript
Expand Down Expand Up @@ -104,3 +120,22 @@ fuckAdBlock.on(detected, fn);
fuckAdBlock.onDetected(fn);
fuckAdBlock.onNotDetected(fn);
```

Instance
---------------------
*(Available only from version 3.1 and more)*
By default, FuckAdBlock is instantiated automatically.
To block this automatic instantiation, simply create a variable "fuckAdBlock" with a value (null, false, ...) before importing the script.
```html
<script>var fuckAdBlock = false;</script>
<script src="./fuckadblock.js"></script>
```
After that, you are free to create your own instances:
```javascript
fuckAdBlock = new FuckAdBlock;
// and|or
myFuckAdBlock = new FuckAdBlock({
checkOnLoad: true,
resetOnEnd: true
});
```
36 changes: 30 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
{
"name": "FuckAdBlock",
"author": ["Valentin Allaire <valentin.allaire@sitexw.fr>"],
"version": "3.0.3",
"main": "fuckadblock.js",
"name": "fuck-adblock",
"version": "3.1.0",
"description": "Detects ad blockers (AdBlock, ...)",
"authors": [{
"name" : "Valentin Allaire",
"email" : "valentin.allaire@sitexw.fr",
"homepage" : "http://sitexw.fr/"
}],
"license": "MIT",
"keywords": [
"adblock",
"advertising",
"ad",
"block",
"lock",
"detection",
"detecting"
],
"main": "fuckadblock.js",
"ignore": [
"package.json"
]
"package.json",
"README.md",
"test.html"
],
"homepage": "https://github.com/sitexw/FuckAdBlock",
"repository": {
"type": "git",
"url": "git://github.com/sitexw/FuckAdBlock.git"
},
"bugs": {
"url": "https://github.com/sitexw/FuckAdBlock/issues"
}
}
89 changes: 45 additions & 44 deletions fuckadblock.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
/*
FuckAdBlock 3.0.3
FuckAdBlock 3.1.0
http://github.com/sitexw/FuckAdBlock
*/

(function(window) {
if(window.fuckAdBlock !== undefined) {
return;
}

var FuckAdBlock = function(options) {
this._options = {
checkOnLoad: false,
resetOnEnd: false,
loopCheckTime: 50,
loopMaxNumber: 5,
baitClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links',
baitStyle: 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;'
};
this._var = {
version: '3.1.0',
bait: null,
checking: false,
loop: null,
loopNumber: 0,
event: { detected: [], notDetected: [] }
};
if(options !== undefined) {
this.setOption(options);
}

var self = this;
var eventCallback = function() {
setTimeout(function() {
Expand All @@ -26,51 +37,34 @@ http://github.com/sitexw/FuckAdBlock
}
}, 1);
};
if(window.addEventListener) {
if(window.addEventListener !== undefined) {
window.addEventListener('load', eventCallback, false);
} else {
window.attachEvent('onload', eventCallback);
}
};
FuckAdBlock.prototype._options = {
checkOnLoad: true,
resetOnEnd: true,
loopCheckTime: 50,
loopMaxNumber: 5,
baitClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links',
baitStyle: 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;'
};
FuckAdBlock.prototype._var = {
version: '3.0.3',
bait: null,
checking: false,
loop: null,
loopNumber: 0,
event: {
detected: [],
notDetected: []
}
};
FuckAdBlock.prototype._options = null;
FuckAdBlock.prototype._var = null;
FuckAdBlock.prototype._bait = null;

FuckAdBlock.prototype.setOption = function(options, value) {
if(value !== undefined) {
var key = options;
options = {};
options[key] = value;
}
for(option in options) {
for(var option in options) {
this._options[option] = options[option];
}
return this;
};

FuckAdBlock.prototype._creatBait = function() {
var bait = document.createElement('div');
bait.setAttribute('class', this._options.baitClass);
bait.setAttribute('style', this._options.baitStyle);
this._var.bait = window.document.body.appendChild(bait);

this._var.bait.offsetParent;
this._var.bait.offsetHeight;
this._var.bait.offsetLeft;
Expand All @@ -83,21 +77,21 @@ http://github.com/sitexw/FuckAdBlock
window.document.body.removeChild(this._var.bait);
this._var.bait = null;
};

FuckAdBlock.prototype.check = function(loop) {
if(loop === undefined) {
loop = true;
}

if(this._var.checking === true) {
return false;
}
this._var.checking = true;

if(this._var.bait === null) {
this._creatBait();
}

var self = this;
this._var.loopNumber = 0;
if(loop === true) {
Expand All @@ -106,16 +100,16 @@ http://github.com/sitexw/FuckAdBlock
}, this._options.loopCheckTime);
}
this._checkBait(loop);

return true;
};
FuckAdBlock.prototype._checkBait = function(loop) {
var detected = false;

if(this._var.bait === null) {
this._creatBait();
}

if(window.document.body.getAttribute('abp') !== null
|| this._var.bait.offsetParent === null
|| this._var.bait.offsetHeight == 0
Expand All @@ -133,7 +127,7 @@ http://github.com/sitexw/FuckAdBlock
detected = true;
}
}

if(loop === true) {
this._var.loopNumber++;
if(this._var.loopNumber >= this._options.loopMaxNumber) {
Expand All @@ -142,7 +136,7 @@ http://github.com/sitexw/FuckAdBlock
this._var.loopNumber = 0;
}
}

if(detected === true) {
if(loop === true) {
this._var.checking = false;
Expand All @@ -157,11 +151,11 @@ http://github.com/sitexw/FuckAdBlock
this.emitEvent(false);
}
};

FuckAdBlock.prototype.emitEvent = function(detected) {
var fns = this._var.event[(detected===true?'detected':'notDetected')];
for(var i in fns) {
if (fns.hasOwnProperty(i)) {
if(fns.hasOwnProperty(i)) {
fns[i]();
}
}
Expand All @@ -174,7 +168,7 @@ http://github.com/sitexw/FuckAdBlock
this._var.event.detected = [];
this._var.event.notDetected = [];
};

FuckAdBlock.prototype.on = function(detected, fn) {
this._var.event[(detected===true?'detected':'notDetected')].push(fn);
return this;
Expand All @@ -185,6 +179,13 @@ http://github.com/sitexw/FuckAdBlock
FuckAdBlock.prototype.onNotDetected = function(fn) {
return this.on(false, fn);
};

window.fuckAdBlock = new FuckAdBlock();

window.FuckAdBlock = FuckAdBlock;

if(window.fuckAdBlock === undefined) {
window.fuckAdBlock = new FuckAdBlock({
checkOnLoad: true,
resetOnEnd: true
});
}
})(window);
52 changes: 30 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
{
"name": "FuckAdBlock",
"version": "3.0.3",
"description": "Detects ad blockers",
"main": "fuckadblock.js",
"license": "MIT",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/sitexw/FuckAdBlock.git"
},
"keywords": [
"ad",
"block",
"detection"
],
"author": "Valentin Allaire <valentin.allaire@sitexw.fr>",
"bugs": {
"url": "https://github.com/sitexw/FuckAdBlock/issues"
},
"homepage": "https://github.com/sitexw/FuckAdBlock"
"name": "fuckadblock",
"version": "3.1.0",
"description": "Detects ad blockers (AdBlock, ...)",
"author": {
"name" : "Valentin Allaire",
"email" : "valentin.allaire@sitexw.fr",
"url" : "http://sitexw.fr/"
},
"license": "MIT",
"keywords": [
"adblock",
"advertising",
"ad",
"block",
"lock",
"detection",
"detecting"
],
"main": "fuckadblock.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"homepage": "https://github.com/sitexw/FuckAdBlock",
"repository": {
"type": "git",
"url": "git://github.com/sitexw/FuckAdBlock.git"
},
"bugs": {
"url": "https://github.com/sitexw/FuckAdBlock/issues"
}
}
Loading

0 comments on commit 35378d1

Please sign in to comment.