Skip to content

Commit c01bcfc

Browse files
committed
Merge pull request #1 from sitexw/v3.x
Update to v3.2.0
2 parents 26d138e + bbc5891 commit c01bcfc

File tree

6 files changed

+119
-42
lines changed

6 files changed

+119
-42
lines changed

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BlockAdBlock (v3.1.1)
1+
BlockAdBlock (v3.2.0)
22
===========
33

44
([FuckAdBlock](https://github.com/sitexw/FuckAdBlock) same project but with a more convenient name)
@@ -59,9 +59,10 @@ if(typeof blockAdBlock === 'undefined') {
5959
}
6060

6161
// Change the options
62-
blockAdBlock.setOptions('checkOnLoad', false);
62+
blockAdBlock.setOption('checkOnLoad', false);
6363
// and|or
64-
blockAdBlock.setOptions({
64+
blockAdBlock.setOption({
65+
debug: true,
6566
checkOnLoad: false,
6667
resetOnEnd: false
6768
});
@@ -89,6 +90,9 @@ baitClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads
8990

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

9498
Method available

blockadblock.js

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* BlockAdBlock 3.1.1
2+
* BlockAdBlock 3.2.0
33
* Copyright (c) 2015 Valentin Allaire <valentin.allaire@sitexw.fr>
44
* Released under the MIT license
55
* https://github.com/sitexw/BlockAdBlock
@@ -13,10 +13,11 @@
1313
loopCheckTime: 50,
1414
loopMaxNumber: 5,
1515
baitClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links',
16-
baitStyle: 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;'
16+
baitStyle: 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;',
17+
debug: false
1718
};
1819
this._var = {
19-
version: '3.1.1',
20+
version: '3.2.0',
2021
bait: null,
2122
checking: false,
2223
loop: null,
@@ -30,6 +31,9 @@
3031
var eventCallback = function() {
3132
setTimeout(function() {
3233
if(self._options.checkOnLoad === true) {
34+
if(self._options.debug === true) {
35+
self._log('onload->eventCallback', 'A check loading is launched');
36+
}
3337
if(self._var.bait === null) {
3438
self._creatBait();
3539
}
@@ -49,6 +53,10 @@
4953
BlockAdBlock.prototype._var = null;
5054
BlockAdBlock.prototype._bait = null;
5155

56+
BlockAdBlock.prototype._log = function(method, message) {
57+
console.log('[BlockAdBlock]['+method+'] '+message);
58+
};
59+
5260
BlockAdBlock.prototype.setOption = function(options, value) {
5361
if(value !== undefined) {
5462
var key = options;
@@ -57,6 +65,9 @@
5765
}
5866
for(var option in options) {
5967
this._options[option] = options[option];
68+
if(this._options.debug === true) {
69+
this._log('setOption', 'The option "'+option+'" he was assigned to "'+options[option]+'"');
70+
}
6071
}
6172
return this;
6273
};
@@ -74,18 +85,33 @@
7485
this._var.bait.offsetWidth;
7586
this._var.bait.clientHeight;
7687
this._var.bait.clientWidth;
88+
89+
if(this._options.debug === true) {
90+
this._log('_creatBait', 'Bait has been created');
91+
}
7792
};
7893
BlockAdBlock.prototype._destroyBait = function() {
7994
window.document.body.removeChild(this._var.bait);
8095
this._var.bait = null;
96+
97+
if(this._options.debug === true) {
98+
this._log('_destroyBait', 'Bait has been removed');
99+
}
81100
};
82101

83102
BlockAdBlock.prototype.check = function(loop) {
84103
if(loop === undefined) {
85104
loop = true;
86105
}
87106

107+
if(this._options.debug === true) {
108+
this._log('check', 'An audit was requested '+(loop===true?'with a':'without')+' loop');
109+
}
110+
88111
if(this._var.checking === true) {
112+
if(this._options.debug === true) {
113+
this._log('check', 'A check was canceled because there is already an ongoing');
114+
}
89115
return false;
90116
}
91117
this._var.checking = true;
@@ -101,7 +127,12 @@
101127
self._checkBait(loop);
102128
}, this._options.loopCheckTime);
103129
}
104-
this._checkBait(loop);
130+
setTimeout(function() {
131+
self._checkBait(loop);
132+
}, 1);
133+
if(this._options.debug === true) {
134+
this._log('check', 'A check is in progress ...');
135+
}
105136

106137
return true;
107138
};
@@ -130,33 +161,52 @@
130161
}
131162
}
132163

164+
if(this._options.debug === true) {
165+
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'));
166+
}
167+
133168
if(loop === true) {
134169
this._var.loopNumber++;
135170
if(this._var.loopNumber >= this._options.loopMaxNumber) {
136-
clearInterval(this._var.loop);
137-
this._var.loop = null;
138-
this._var.loopNumber = 0;
171+
this._stopLoop();
139172
}
140173
}
141174

142175
if(detected === true) {
143-
if(loop === true) {
144-
this._var.checking = false;
145-
}
176+
this._stopLoop();
146177
this._destroyBait();
147178
this.emitEvent(true);
148-
} else if(this._var.loop === null || loop === false) {
149179
if(loop === true) {
150180
this._var.checking = false;
151181
}
182+
} else if(this._var.loop === null || loop === false) {
152183
this._destroyBait();
153184
this.emitEvent(false);
185+
if(loop === true) {
186+
this._var.checking = false;
187+
}
188+
}
189+
};
190+
BlockAdBlock.prototype._stopLoop = function(detected) {
191+
clearInterval(this._var.loop);
192+
this._var.loop = null;
193+
this._var.loopNumber = 0;
194+
195+
if(this._options.debug === true) {
196+
this._log('_stopLoop', 'A loop has been stopped');
154197
}
155198
};
156199

157200
BlockAdBlock.prototype.emitEvent = function(detected) {
201+
if(this._options.debug === true) {
202+
this._log('emitEvent', 'An event with a '+(detected===true?'positive':'negative')+' detection was called');
203+
}
204+
158205
var fns = this._var.event[(detected===true?'detected':'notDetected')];
159206
for(var i in fns) {
207+
if(this._options.debug === true) {
208+
this._log('emitEvent', 'Call function '+(parseInt(i)+1)+'/'+fns.length);
209+
}
160210
if(fns.hasOwnProperty(i)) {
161211
fns[i]();
162212
}
@@ -169,10 +219,18 @@
169219
BlockAdBlock.prototype.clearEvent = function() {
170220
this._var.event.detected = [];
171221
this._var.event.notDetected = [];
222+
223+
if(this._options.debug === true) {
224+
this._log('clearEvent', 'The event list has been cleared');
225+
}
172226
};
173227

174228
BlockAdBlock.prototype.on = function(detected, fn) {
175229
this._var.event[(detected===true?'detected':'notDetected')].push(fn);
230+
if(this._options.debug === true) {
231+
this._log('on', 'A type of event "'+(detected===true?'detected':'notDetected')+'" was added');
232+
}
233+
176234
return this;
177235
};
178236
BlockAdBlock.prototype.onDetected = function(fn) {

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blockadblock",
3-
"version": "3.1.1",
3+
"version": "3.2.0",
44
"description": "Detects ad blockers (AdBlock, ...)",
55
"authors": [{
66
"name" : "Valentin Allaire",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blockadblock",
3-
"version": "3.1.1",
3+
"version": "3.2.0",
44
"description": "Detects ad blockers (AdBlock, ...)",
55
"author": {
66
"name" : "Valentin Allaire",

0 commit comments

Comments
 (0)