-
-
Save mokoshalb/71826fe33206b733fe9781f1b3cc4382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WARNING: jquery required! | |
// jquery cdn: https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js | |
function detectAdblock(selector) { | |
return ($($(selector)[0]).css('display') == 'none'); | |
} | |
function preventAdblockStyles(selector) { | |
$(selector).attr('style', 'display: block!important;visibility: visible!important;text-decoration: none!important;'); | |
} | |
function antiAdblock(opt) { | |
opt = opt || {}; | |
opt.target = opt.target || '_blank'; | |
var rand_id = Math.random().toString(36).substring(7); | |
var banner = '<div id="' + rand_id + '" style="width:' + opt.w + 'px!important;height:' + opt.h + 'px!important;background-image:url(\'' + opt.img + '\') !important;background-repeat:repeat repeat!important;background-position:center center!important;cursor:pointer!important;" onclick="window.open(\'' + opt.link + '\', \'' + opt.target + '\')" title="' + opt.title + '">' + (opt.fuck_adblock ? '<span style="background:white;float: right;font-size: 10px;font-weight: bold;opacity: 0.8;" title="Мы оставляем за собой право показывать рекламу на сайтах где Вы используете AdBlock"><img src="http://savepic.ru/9710734.png" style="width: 25px;">Реклама от AdBlock</span>' : '') + '</div>'; | |
$(opt.selector).append(banner); | |
return rand_id; | |
} | |
// usage example | |
// when page fully loaded | |
$(window).load(function() { | |
console.info('page load'); | |
var adblock_detected = false; | |
adblock_detected = detectAdblock('ins.adsbygoogle'); // google ads | |
console.info('adblock detected: ' + adblock_detected); | |
// if adblock detected | |
if (adblock_detected) { | |
preventAdblockStyles('ins.adsbygoogle'); | |
// create aliexpress ad | |
antiAdblock({ | |
selector: 'body', // ad selector (where ad will be appended) | |
w: 728, // ad width | |
h: 90, // ad height | |
link: 'https://alitems.com/g/b611e78a21c46540cbbd16525dc3e8/?i=4', // ad link | |
img: 'https://alitems.com/b/b611e78a21c46540cbbd16525dc3e8/', // ad img | |
title: 'С любовью от Aliexpress', // ad title | |
fuck_adblock: true // show 'Реклама от AdBlock' | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment