diff --git a/LICENSE b/LICENSE index d8b688d..7ce5af3 100644 --- a/LICENSE +++ b/LICENSE @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/README.md b/README.md index 874f7c5..fdf6bf7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -BlockAdBlock (v3.1.1) +BlockAdBlock (v3.2.0) =========== ([FuckAdBlock](https://github.com/sitexw/FuckAdBlock) same project but with a more convenient name) @@ -59,9 +59,10 @@ if(typeof blockAdBlock === 'undefined') { } // Change the options -blockAdBlock.setOptions('checkOnLoad', false); +blockAdBlock.setOption('checkOnLoad', false); // and|or -blockAdBlock.setOptions({ +blockAdBlock.setOption({ + debug: true, checkOnLoad: false, resetOnEnd: false }); @@ -89,6 +90,9 @@ baitClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads // CSS style used to hide the bait of the users baitStyle: 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;' + +// Displays the debug in the console (available only from version 3.2 and more) +debug: false ``` Method available diff --git a/blockadblock.js b/blockadblock.js index 8f206a6..e938432 100644 --- a/blockadblock.js +++ b/blockadblock.js @@ -1,5 +1,5 @@ /* - * BlockAdBlock 3.1.1 + * BlockAdBlock 3.2.0 * Copyright (c) 2015 Valentin Allaire * Released under the MIT license * https://github.com/sitexw/BlockAdBlock @@ -13,10 +13,11 @@ 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;' + baitStyle: 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;', + debug: false }; this._var = { - version: '3.1.1', + version: '3.2.0', bait: null, checking: false, loop: null, @@ -30,6 +31,9 @@ var eventCallback = function() { setTimeout(function() { if(self._options.checkOnLoad === true) { + if(self._options.debug === true) { + self._log('onload->eventCallback', 'A check loading is launched'); + } if(self._var.bait === null) { self._creatBait(); } @@ -49,6 +53,10 @@ BlockAdBlock.prototype._var = null; BlockAdBlock.prototype._bait = null; + BlockAdBlock.prototype._log = function(method, message) { + console.log('[BlockAdBlock]['+method+'] '+message); + }; + BlockAdBlock.prototype.setOption = function(options, value) { if(value !== undefined) { var key = options; @@ -57,6 +65,9 @@ } for(var option in options) { this._options[option] = options[option]; + if(this._options.debug === true) { + this._log('setOption', 'The option "'+option+'" he was assigned to "'+options[option]+'"'); + } } return this; }; @@ -74,10 +85,18 @@ this._var.bait.offsetWidth; this._var.bait.clientHeight; this._var.bait.clientWidth; + + if(this._options.debug === true) { + this._log('_creatBait', 'Bait has been created'); + } }; BlockAdBlock.prototype._destroyBait = function() { window.document.body.removeChild(this._var.bait); this._var.bait = null; + + if(this._options.debug === true) { + this._log('_destroyBait', 'Bait has been removed'); + } }; BlockAdBlock.prototype.check = function(loop) { @@ -85,7 +104,14 @@ loop = true; } + if(this._options.debug === true) { + this._log('check', 'An audit was requested '+(loop===true?'with a':'without')+' loop'); + } + if(this._var.checking === true) { + if(this._options.debug === true) { + this._log('check', 'A check was canceled because there is already an ongoing'); + } return false; } this._var.checking = true; @@ -101,7 +127,12 @@ self._checkBait(loop); }, this._options.loopCheckTime); } - this._checkBait(loop); + setTimeout(function() { + self._checkBait(loop); + }, 1); + if(this._options.debug === true) { + this._log('check', 'A check is in progress ...'); + } return true; }; @@ -130,33 +161,52 @@ } } + if(this._options.debug === true) { + this._log('_checkBait', 'A check ('+(this._var.loopNumber+1)+'/'+this._options.loopMaxNumber+' ~'+(1+this._var.loopNumber*this._options.loopCheckTime)+'ms) was conducted and detection is '+(detected===true?'positive':'negative')); + } + if(loop === true) { this._var.loopNumber++; if(this._var.loopNumber >= this._options.loopMaxNumber) { - clearInterval(this._var.loop); - this._var.loop = null; - this._var.loopNumber = 0; + this._stopLoop(); } } if(detected === true) { - if(loop === true) { - this._var.checking = false; - } + this._stopLoop(); this._destroyBait(); this.emitEvent(true); - } else if(this._var.loop === null || loop === false) { if(loop === true) { this._var.checking = false; } + } else if(this._var.loop === null || loop === false) { this._destroyBait(); this.emitEvent(false); + if(loop === true) { + this._var.checking = false; + } + } + }; + BlockAdBlock.prototype._stopLoop = function(detected) { + clearInterval(this._var.loop); + this._var.loop = null; + this._var.loopNumber = 0; + + if(this._options.debug === true) { + this._log('_stopLoop', 'A loop has been stopped'); } }; BlockAdBlock.prototype.emitEvent = function(detected) { + if(this._options.debug === true) { + this._log('emitEvent', 'An event with a '+(detected===true?'positive':'negative')+' detection was called'); + } + var fns = this._var.event[(detected===true?'detected':'notDetected')]; for(var i in fns) { + if(this._options.debug === true) { + this._log('emitEvent', 'Call function '+(parseInt(i)+1)+'/'+fns.length); + } if(fns.hasOwnProperty(i)) { fns[i](); } @@ -169,10 +219,18 @@ BlockAdBlock.prototype.clearEvent = function() { this._var.event.detected = []; this._var.event.notDetected = []; + + if(this._options.debug === true) { + this._log('clearEvent', 'The event list has been cleared'); + } }; BlockAdBlock.prototype.on = function(detected, fn) { this._var.event[(detected===true?'detected':'notDetected')].push(fn); + if(this._options.debug === true) { + this._log('on', 'A type of event "'+(detected===true?'detected':'notDetected')+'" was added'); + } + return this; }; BlockAdBlock.prototype.onDetected = function(fn) { diff --git a/bower.json b/bower.json index 2960fff..592213e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "blockadblock", - "version": "3.1.1", + "version": "3.2.0", "description": "Detects ad blockers (AdBlock, ...)", "authors": [{ "name" : "Valentin Allaire", diff --git a/package.json b/package.json index 15f8398..273fe9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blockadblock", - "version": "3.1.1", + "version": "3.2.0", "description": "Detects ad blockers (AdBlock, ...)", "author": { "name" : "Valentin Allaire", diff --git a/test.html b/test.html index 036b55f..65a2323 100644 --- a/test.html +++ b/test.html @@ -1,13 +1,14 @@ - BlockAdBlock 3.1.1 + BlockAdBlock 3.2.0 - + +
-

BlockAdBlock 3.1.1

+

BlockAdBlock 3.2.0

- FuckAdBlock + FuckAdBlock     Online example     @@ -56,8 +60,8 @@

Publicity example

- - + +
@@ -74,11 +78,11 @@

Install via

Manual:

Download "blockadblock.js" and add it to your website.

Bower:

-
bower install blockadblock
+
bower install fuck-adblock

Node.js/io.js:

npm install blockadblock

Code example

-
// Function called if AdBlock is not detected
+
// Function called if AdBlock is not detected
 function adBlockNotDetected() {
 	alert('AdBlock is not enabled');
 }
@@ -103,14 +107,15 @@ 

Code example

} // Change the options -blockAdBlock.setOptions('checkOnLoad', false); +blockAdBlock.setOption('checkOnLoad', false); // and|or -blockAdBlock.setOptions({ +blockAdBlock.setOption({ + debug: true, checkOnLoad: false, resetOnEnd: false -});
+});

Default options

-
// At launch, check if AdBlock is enabled
+
// At launch, check if AdBlock is enabled
 // Uses the method blockAdBlock.check()
 checkOnLoad: true
 
@@ -129,9 +134,12 @@ 

Default options

// CSS style used to hide the bait of the users baitStyle: 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;' -
+ +// Displays the debug in the console (available only from version 3.2 and more) +debug: false +

Method available

-
// Allows to set options
+
// Allows to set options
 // #options: string|object
 // #value:   string
 blockAdBlock.setOption(options, value);
@@ -157,46 +165,48 @@ 

Method available

// Similar to blockAdBlock.on(true|false, fn) blockAdBlock.onDetected(fn); -blockAdBlock.onNotDetected(fn);
+blockAdBlock.onNotDetected(fn);

Instance

(Available only from version 3.1 and more)
By default, BlockAdBlock is instantiated automatically.
To block this automatic instantiation, simply create a variable "blockAdBlock" with a value (null, false, ...) before importing the script.

-
<script>var blockAdBlock = false;</script>
-<script src="./blockadblock.js"></script>
+
<script>var blockAdBlock = false;</script>
+<script src="./blockadblock.js"></script>
After that, you are free to create your own instances: -
blockAdBlock = new BlockAdBlock;
+
blockAdBlock = new BlockAdBlock;
 // and|or
 myBlockAdBlock = new BlockAdBlock({
 	checkOnLoad: true,
 	resetOnEnd: true
-});
+});
+ + + \ No newline at end of file