FuckAdBlock 介绍
FuckAdBlock 允许你检测扩展的广告拦截器(AdBlock 或者其他)。
在线示例:http://sitexw.fr/fuckadblock/
(此项目还有个更方便的名字 BlockAdBlock)
支持
Google Chrome
Mozilla Firefox
Internet Explorer (8+)
Safari
Opera
安装
手动
下载 fuckadblock.js 并添加到你的网站中
Bower:
bower install fuck-adblock
Node.js/io.js:
npm install fuckadblock
代码示例
// 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 'fuckadblock.js' // If the file is not called, the variable does not exist 'fuckAdBlock' // This means that AdBlock is present if(typeof fuckAdBlock === 'undefined') { adBlockDetected(); } else { fuckAdBlock.onDetected(adBlockDetected); fuckAdBlock.onNotDetected(adBlockNotDetected); // and|or fuckAdBlock.on(true, adBlockDetected); fuckAdBlock.on(false, adBlockNotDetected); // and|or fuckAdBlock.on(true, adBlockDetected).onNotDetected(adBlockNotDetected); } // Change the options fuckAdBlock.setoption('checkOnLoad', false); // and|or fuckAdBlock.setoption({ debug: true, checkOnLoad: false, resetonEnd: false });
默认选项
// At launch, check if AdBlock is enabled // Uses the method fuckAdBlock.check() checkOnLoad: true // At the end of the check, is that it removes all events added ? resetonEnd: true // The number of milliseconds between each check loopCheckTime: 50 // The number of negative checks after which there is considered that AdBlock is not enabled // Time (ms) = 50*(5-1) = 200ms (per default) loopMaxnumber: 5 // CSS class used by the bait caught AdBlock baitClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links' // 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
提供的方法
// Allows to set options // #options: string|object // #value: string fuckAdBlock.setoption(options, value); // Allows to check if AdBlock is enabled // The parameter 'loop' allows checking without loop several times according to the value of 'loopMaxnumber' // Example: loop=true => time~=200ms (time varies depending on the configuration) // loop=false => time~=1ms // #loop: boolean (default: true) fuckAdBlock.check(loop); // Allows to manually simulate the presence of AdBlock or not // #detected: boolean (AdBlock is detected ?) fuckAdBlock.emitEvent(detected); // Allows to clear all events added via methods 'on', 'onDetected' and 'onNotDetected' fuckAdBlock.clearEvent(); // Allows to add an event if AdBlock is detected // #detected: boolean (true: detected, false: not detected) // #fn: function fuckAdBlock.on(detected, fn); // Similar to fuckAdBlock.on(true|false, fn) fuckAdBlock.onDetected(fn); fuckAdBlock.onNotDetected(fn);
FuckAdBlock 官网
https://github.com/sitexw/FuckAdBlock
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。