Skip to content

Instantly share code, notes, and snippets.

@pafnuty
Last active August 29, 2015 14:15
Show Gist options
  • Save pafnuty/68c38c08c155569cbb41 to your computer and use it in GitHub Desktop.
Save pafnuty/68c38c08c155569cbb41 to your computer and use it in GitHub Desktop.
Обходим ABlock
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.not-empty {
/*height: 15px;*/
}
.mfp-white {
width: 300px;
padding: 20px;
background: #fff;
margin: 0 auto;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/magnific-popup.min.css">
</head>
<body>
<div class="not-empty">этот не заблокирован</div>
<div class="ad1"></div>
<div class="not-empty">
<div id="bn_9a50928f6a">загрузка...</div>
<script async src="http://recreativ.ru/rcode.9a50928f6a.js"></script>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/jquery.magnific-popup.min.js"></script>
<script>
/**
* Плагин : jQuery.antiHide
* Версия : 1.0 (19.02.2015)
* Автор : ПафНутиЙ
* Twitter : @pafnuty_name
* Назначение : Детектор недостаточной, по мнению вебмастера, высоты блоков на сайте (AdBlock-детектор)
*/
;(function ($, window, document, undefined) {
var blocked = false,
defaults = {
minHeight: 0,
callback: function () {}
},
methods = {
init: function (options) {
var props = $.extend({}, defaults, options),
_this = this,
_run = function () {
methods.run(_this, props);
};
$(window).on('load.antiHide', _this, _run);
return this;
},
run: function (elements, options) {
$.each(elements, function () {
var $el = $(this),
height = $(this).height();
if (height <= options.minHeight) {
blocked = true;
options.callback.call(this);
return false;
};
});
if (blocked) {
return true;
};
return false;
}
};
$.fn.antiHide = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
}
else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
}
else {
$.error('Метод с именем ' + method + ' не существует для jQuery.antiHide');
}
};
})(jQuery, window, document);
jQuery(document).ready(function ($) {
$('.ad1').antiHide({
callback: function () {
// doPipUp();
}
});
$('.not-empty').antiHide({
// minHeight: 20, // Минимальная высота блока, при которой будет срабатывать функция
callback: function () { // Функиция, срабатывающая при едостаточной высоте блока
doPipUp();
}
});
});
function doPipUp () {
$.magnificPopup.open({
items: {
src: '<div class="mfp-white">Чувак, выключи AdBlock</div>'
},
type: 'inline'
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment