Гарин
Разметка:
<div class="banner">
<div>
<script type="text/javascript">
var ad_idzone = "1886044",
ad_width = "300",
ad_height = "250";
</script>
<script type="text/javascript" src="https://ads.exoclick.com/ads.js"></script>
<noscript><a href="http://main.exoclick.com/img-click.php?idzone=1886044" target="_blank"><img src="https://syndication.exoclick.com/ads-iframe-display.php?idzone=1886044&output=img&type=300x250" width="300" height="250"></a></noscript>
<iframe style="border:0px solid #000000" frameborder="0" scrolling="no" width="300" height="250" src="about:blank"></iframe><script type="text/javascript">
ExoLoader.addZone({"type": "banner", "width":"300", "height":"250", "idzone":"1886044"});
</script>
</div>
</div>
Код скрипта полностью:
var ExoLoader = (function () {
var version = '2.4';
var setCookie = function (name, value, minutes_ttl) {
var exdate = new Date();
exdate.setMinutes(exdate.getMinutes() + minutes_ttl);
var c_value = encodeURI(value) + "; expires=" + exdate.toUTCString() + "; path=/";
document.cookie = name + "=" + c_value;
};
var openLink = function (event, dest) {
var ie = (function(){
var undef,rv = -1; // Return value assumes failure.
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
var trident = ua.indexOf('Trident/');
if (msie > 0) {
// IE 10 or older => return version number
rv = parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
} else if (trident > 0) {
// IE 11 (or newer) => return version number
var rvNum = ua.indexOf('rv:');
rv = parseInt(ua.substring(rvNum + 3, ua.indexOf('.', rvNum)), 10);
}
return ((rv > -1) ? rv : undef);
}());
if ( typeof(event) != "undefined" ) {
event.returnValue = false;
if ( event.preventDefault ) {
event.preventDefault();
}
}
var f = document.createElement("form");
if (ie) {
f.setAttribute("action", dest);
} else {
f.setAttribute("action", "data:text/html;base64," + btoa("<html><meta http-equiv=\"refresh\" content=\"0; url=" + dest + "\"></html>"));
}
f.setAttribute("method", "post");
f.setAttribute("target", "_blank");
document.getElementsByTagName("body").item(0).appendChild(f);
f.submit();
document.getElementsByTagName("body").item(0).removeChild(f);
return false;
};
var ad_types = ['banner', 'popunder'];
var zone_params = {};
var dom = {};
var debug_messages = [];
var addDebugMessage = function (message) {
var date = new Date();
debug_messages.push(date.toISOString() + ": " + message);
};
var stringify = function (value) {
var reassign_when_finished = false;
if (typeof Array.prototype.toJSON !== 'undefined') {
reassign_when_finished = true;
var array_to_json = Array.prototype.toJSON;
delete Array.prototype.toJSON;
}
var val = JSON.stringify(value);
if (reassign_when_finished) {
Array.prototype.toJSON = array_to_json;
}
return val;
};
var loader = {
cookie_name: "exo_zones",
addZone: function(params) {
if (typeof exo99HL3903jjdxtrnLoad != "undefined" && exo99HL3903jjdxtrnLoad) {
return false;
}
if (typeof params != 'object'
|| typeof params.type == 'undefined'
|| ad_types.indexOf(params.type) == -1
) {
addDebugMessage("addZone() invalid params");
return false;
}
var scripts = document.getElementsByTagName('script');
// The current <script> tag where the method is called
var here = scripts[ scripts.length - 1 ];
var type = params.type;
delete params.type;
if (typeof zone_params[type] == 'undefined') {
dom[type] = [];
zone_params[type] = [];
}
zone_params[type].push(params);
if (type == 'banner') {
var iframe = document.createElement('iframe');
iframe.setAttribute('style', 'border:0px solid #000000');
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('scrolling', 'no');
iframe.setAttribute('width', params.width);
iframe.setAttribute('height', params.height);
iframe.setAttribute('src', 'about:blank');
here.parentNode.insertBefore(iframe, here);
dom[type].push(iframe);
}
addDebugMessage("addZone() " + type + " " + params.idzone + " added");
return true;
},
renderBannerZone: function (id, img_data, dest) {
addDebugMessage("renderBannerZone(" + id + ", ...) called");
if (typeof dom['banner'][id] == 'undefined'
|| typeof img_data != 'object'
|| typeof img_data.img == 'undefined'
|| typeof img_data.content_type == 'undefined'
|| typeof dest == 'undefined'
) {
addDebugMessage("renderBannerZone(" + id + ") corrupt params");
return false;
}
var doc = dom['banner'][id].contentWindow.document;
doc.body.style.margin = "0px";
doc.body.innerHTML = '' +
'<a id="dest" href="javascript:void(0)" target="_blank" border="0">' +
'<img width="' + zone_params['banner'][id].width + '" height = "' + zone_params['banner'][id].height + '" src = "data:' + img_data.content_type + ';base64,' + img_data.img + '">' +
'</a>';
doc.getElementById('dest').onclick = (function(dest) {
return function(event) {
openLink(event, dest);
};
})(dest);
},
renderBannerZones: function (response) {
addDebugMessage("renderBannerZones() called");
if (typeof response != 'object'
|| typeof response.zones != 'object'
|| typeof response.images != 'object'
) {
addDebugMessage("renderBannerZones() empty zones or images");
return;
}
for (var i = 0; i < response.zones.length; i++) {
var img_key = response.zones[i].img_key;
this.renderBannerZone(i, response.images[img_key], response.zones[i].dest);
}
},
serve: function(params) {
if (typeof exo99HL3903jjdxtrnLoad != "undefined" && exo99HL3903jjdxtrnLoad) {
addDebugMessage("serve() ad blocker not enabled");
return false;
}
var zones_added = false;
for (var type_index = 0; type_index < ad_types.length; type_index++) {
if (typeof zone_params[ad_types[type_index]] !== 'undefined' && zone_params[ad_types[type_index]].length > 0) {
zones_added = true;
break;
}
}
if (!zones_added) {
addDebugMessage("serve() no zones added");
return false;
}
window.exoNoExternalUI38djdkjDDJsio96 = true;
addDebugMessage("serve() called");
setCookie(this.cookie_name, stringify(zone_params), 5);
var loadDataScript = function () {
var dataScript = document.createElement("script");
dataScript.async = true;
dataScript.setAttribute('type', 'text/javascript');
dataScript.setAttribute('src', params.script_url);
dataScript.onload = function(){
addDebugMessage("serve() hosted script loaded");
};
document.getElementsByTagName("body").item(0).appendChild(dataScript);
};
if (window.addEventListener) {
window.addEventListener("load", loadDataScript, false);
} else if (window.attachEvent) {
window.attachEvent("onload", loadDataScript);
} else {
window.onload = loadDataScript;
}
return true;
},
getDebug: function() {
for (var i = 0; i < debug_messages.length; i++) {
console.log(debug_messages[i]);
}
},
getVersion: function() {
return version;
}
};
return loader;
})();
Так он вызывается:
ExoLoader.renderBannerZones({
// Здесь урлы для слива и картинки в base64
});
А теперь внимание вопрос: какие проблемы на сервере могут помешать этому коду работать?
Гарин
Mit писал:
backend_loader.php
Нет не забыл. На tube18.sex он назывется sex_ad.php и возвращает вот это:
Код:
ExoLoader.renderBannerZones({
zones": [{
"dest": "урл для слива",
"img_key": 0
},
...
],
"images": {
"0": {
"img": "картинка в base64",
"content_type": "image\/gif"
}
}
});
Загружается все это дело путем создания тэга script с src="sex_ad.php" и вставки его в дом.
serve: function(params) {
if (typeof exo99HL3903jjdxtrnLoad != "undefined" && exo99HL3903jjdxtrnLoad) {
addDebugMessage("serve() ad blocker not enabled");
return false;
}
var zones_added = false;
for (var type_index = 0; type_index < ad_types.length; type_index++) {
if (typeof zone_params[ad_types[type_index]] !== 'undefined' && zone_params[ad_types[type_index]].length > 0) {
zones_added = true;
break;
}
}
if (!zones_added) {
addDebugMessage("serve() no zones added");
return false;
}
window.exoNoExternalUI38djdkjDDJsio96 = true;
addDebugMessage("serve() called");
setCookie(this.cookie_name, stringify(zone_params), 5);
var loadDataScript = function () {
var dataScript = document.createElement("script");
dataScript.async = true;
dataScript.setAttribute('type', 'text/javascript');
dataScript.setAttribute('src', params.script_url);
dataScript.onload = function(){
addDebugMessage("serve() hosted script loaded");
};
document.getElementsByTagName("body").item(0).appendChild(dataScript);
};
if (window.addEventListener) {
window.addEventListener("load", loadDataScript, false);
} else if (window.attachEvent) {
window.attachEvent("onload", loadDataScript);
} else {
window.onload = loadDataScript;
}
return true;
}
При чем тут версия пхп, курл и т.д. все равно не понятно. Тем не менее программирование по переписке занятие увлекательное, продолжай.