(function () { var getSelfElement = function(){ var scripts = document.getElementsByTagName('script'); for (var i = (scripts.length - 1); i >= 0; i--){ if (scripts[i].src.match(/^https:\/\/srv1.adstuber.com\/test\/3\/load.js/)){ return scripts[i]; } } return false; }; var iframe = document.createElement('iframe'); iframe.style.width = '100%'; iframe.style.height = '0'; iframe.style.border = 'none'; iframe.style.padding = '0'; //iframe.style.display = 'none'; iframe.id = 'adtube_iframe3'; var self_script = getSelfElement(); self_script.parentNode.insertBefore(iframe, self_script); (function () { var article_id = 103; var json_url = 'https://srv1.adstuber.com/at_res.php?spot=1&article=' + article_id + '&_=' + new Date().getTime(); var xhr = new XMLHttpRequest(); xhr.ontimeout = function () { console.error("The adstuber request timed out."); }; xhr.onload = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { at_xhr_success(xhr.response, '', ''); } else { console.error(xhr.statusText); } } }; xhr.open("GET", json_url, true); xhr.timeout = 3000; xhr.responseType = 'json'; xhr.send(null); })(); var at_xhr_success = function(json_data, click_url, view_url){ if (typeof json_data == 'string') { json_data = JSON.parse(json_data); } var xhr = new XMLHttpRequest(); xhr.ontimeout = function () { console.error("The adtuber request timed out."); }; xhr.onload = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { data = xhr.response; if (typeof data == 'string') { data = JSON.parse(data); } var iframe_document = iframe.contentWindow.document; iframe_document.open(); iframe_document.write(data[0]); iframe_document.close(); } else { console.error(xhr.statusText); } } }; xhr.open("POST", 'https://srv1.adstuber.com/test/3/adtube.php?_=' + new Date().getTime(), true); xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); xhr.timeout = 3000; xhr.responseType = 'json'; var at_param = ''; at_param += 'youid=' + json_data.prop.youid; at_param += '&t_user_name=' + encodeURIComponent(json_data.prop.t_user_name); at_param += '&t_user_id=' + encodeURIComponent(json_data.prop.t_user_id); at_param += '&t_summary=' + encodeURIComponent(json_data.prop.t_summary); at_param += '&time=' + encodeURIComponent(json_data.prop.time); at_param += '&youtube_text=' + encodeURIComponent(json_data.prop.yuoutube_text); at_param += '&channel=' + encodeURIComponent(json_data.prop.y_channel_url); at_param += '&t_icon=' + encodeURIComponent(json_data.file.t_icon); for (const prop in json_data.addr) { at_param += '&' + prop + '=' + encodeURIComponent(json_data.addr[prop]); } at_param += '&o_click_url=' + encodeURIComponent(click_url); at_param += '&o_view_url=' + encodeURIComponent(view_url); xhr.send(at_param); }; })();