/** * 애드벌룬 CPA 스크립트 * * @project : adballoon v2 * @author : napro@afreecatv.com * @date : 2019.07.22 */ (function(win, doc) { var listener, eventType = 'DOMContentLoaded', parttern = (doc.documentElement.doScroll ? /^loaded|^c/ : /^loaded|^i|^c/), isLoaded = parttern.test(doc.readyState), callback = function() { var cid = ''; win.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, val) { if (key == 'adb_cid') { cid = val; return; } }); var host = encodeURIComponent(doc.location.protocol + '//' + doc.location.host), frame = doc.createElement('iframe'); frame.id = 'afctv_cpa_proc'; frame.src = 'https://adballoon.afreecatv.com/app/api/afreecatv.cpa.v1.php?host=' + host + '&cid=' + cid; frame.width = 0; frame.height = 0; frame.setAttribute('frameborder', 0); doc.getElementsByTagName('body')[0].appendChild(frame); }; if (isLoaded == false) { doc.addEventListener(eventType, listener = function() { doc.removeEventListener(eventType, listener); isLoaded = true; callback(); }); } else { setTimeout(callback, 0); } win.addEventListener('message', function(evt) { if (evt.origin.replace(/^https?:\/\//, '') == 'adballoon.afreecatv.com') { var param = JSON.parse(evt.data); if (param.status == 200) { if (win.AFCTV.onDone) { win.AFCTV.onDone(param.data); } } else { if (win.AFCTV.onFail) { win.AFCTV.onFail(param.data); } } } }); win.AFCTV = { onDone: null, onFail: null, onAction: function(done, fail) { this.onDone = done; this.onFail = fail; doc.getElementById('afctv_cpa_proc').contentWindow.postMessage('action', '*'); } }; })(window, document);