var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(r) { var t, e, o, a, h, n, c, d = "", C = 0; for (r = Base64._utf8_encode(r); C < r.length; ) a = (t = r.charCodeAt(C++)) >> 2, h = (3 & t) << 4 | (e = r.charCodeAt(C++)) >> 4, n = (15 & e) << 2 | (o = r.charCodeAt(C++)) >> 6, c = 63 & o, isNaN(e) ? n = c = 64 : isNaN(o) && (c = 64), d = d + this._keyStr.charAt(a) + this._keyStr.charAt(h) + this._keyStr.charAt(n) + this._keyStr.charAt(c); return d }, decode: function(r) { var t, e, o, a, h, n, c = "", d = 0; for (r = r.replace(/[^A-Za-z0-9\+\/\=]/g, ""); d < r.length; ) t = this._keyStr.indexOf(r.charAt(d++)) << 2 | (a = this._keyStr.indexOf(r.charAt(d++))) >> 4, e = (15 & a) << 4 | (h = this._keyStr.indexOf(r.charAt(d++))) >> 2, o = (3 & h) << 6 | (n = this._keyStr.indexOf(r.charAt(d++))), c += String.fromCharCode(t), 64 != h && (c += String.fromCharCode(e)), 64 != n && (c += String.fromCharCode(o)); return c = Base64._utf8_decode(c) }, _utf8_encode: function(r) { r = r.replace(/\r\n/g, "\n"); for (var t = "", e = 0; e < r.length; e++) { var o = r.charCodeAt(e); o < 128 ? t += String.fromCharCode(o) : o > 127 && o < 2048 ? (t += String.fromCharCode(o >> 6 | 192), t += String.fromCharCode(63 & o | 128)) : (t += String.fromCharCode(o >> 12 | 224), t += String.fromCharCode(o >> 6 & 63 | 128), t += String.fromCharCode(63 & o | 128)) } return t }, _utf8_decode: function(r) { for (var t = "", e = 0, o = c1 = c2 = 0; e < r.length; ) (o = r.charCodeAt(e)) < 128 ? (t += String.fromCharCode(o), e++) : o > 191 && o < 224 ? (c2 = r.charCodeAt(e + 1), t += String.fromCharCode((31 & o) << 6 | 63 & c2), e += 2) : (c2 = r.charCodeAt(e + 1), c3 = r.charCodeAt(e + 2), t += String.fromCharCode((15 & o) << 12 | (63 & c2) << 6 | 63 & c3), e += 3); return t } }; function noadpassback(errObj, slotInfo) { if (window.location !== window.parent.location) { document.querySelector('section.wrap').style.display = 'none'; window.parent.postMessage("ypa_if_noadpassback", "*"); container = document.createElement('div') container.innerHTML = '' document.body.appendChild(container.firstElementChild) script = document.createElement('script') script.src = 'https://storage.googleapis.com/adnetwork_bucket/yna/advertising.js' document.head.appendChild(script) } } (function() { var loadYpa = { data: { kw: '', title: '', token: '', label: '', config: '', type: '', style: '//zi.media/kwads/css/ypa_index-min.css' }, init: function() { var kw = decodeURI(this.gup('keyword')) , token = this.gup('token') , label = this.gup('label') , style = this.gup('style'); kw && (this.data.kw = decodeURI(kw)); token && (this.data.token = token); label && (this.data.label = label); style && (this.data.style = style); //override this.data.token = "477b327bba97571ba8005c72c22a0b8f"; this.data.label = "2ndpage"; this.data.kw = "iphone"; if( typeof _adbot_backup_keyowrds != "undefined" && _adbot_backup_keyowrds.length > 0 ) { //var searchad = document.getElementById("searchad"); this.data.kw =_adbot_backup_keyowrds[0]; } kw = this.data.kw; this.data.title = kw + " 的搜尋結果"; this.getConfig(); }, configCallback: function(data) { this.data.config = Base64.decode(data.c); this.data.type = data.ty; this.appendHtml(); }, getConfig: function() { var script = document.createElement('script'); //script.src = '//cell.adbottw.net/zi.media_ypa_ty/?partner=' + this.data.token + '&label=' + this.data.label + '&callback=loadYpa.configCallback'; script.src = '//cell.adbot.tw/ypa_ty?partner=' + this.data.token + '&label=' + this.data.label + '&callback=loadYpa.configCallback'; document.getElementsByTagName('head')[0].appendChild(script); }, gup: function(name, href) { href = href || window.location.href; name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(href); return results ? results[1] : ''; }, appendHtml: function() { document.title = this.data.title; var initialDOM = '
'; if (window.location === window.parent.location) { initialDOM += '

' + this.data.title + '

'; this.data.style = '//zi.media/kwads/css/ypa_index-min.css'; } else { this.data.style = '//zi.media/kwads/css/ypa_if-min.css'; } initialDOM += '
'; initialDOM += '
'; //document.body.insertAdjacentHTML('afterbegin', initialDOM); var searchad = document.getElementById("searchad"); searchad.insertAdjacentHTML('afterbegin', initialDOM); this.adCode(); this.monitor(); }, monitor: function() { var keyword = this.data.kw; var ifMonitor = setInterval(function() { var elem = document.activeElement; if (elem && elem.tagName == 'IFRAME') { clearInterval(ifMonitor); if (typeof window.gtag === "function") { window.gtag('event', 'click', { 'event_category': 'ad', 'event_label': keyword }); } } }, 100); }, adCode: function() { var self = this , script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("src", 'https://s.yimg.com/uv/dm/scripts/syndication.js'); document.querySelector('body').appendChild(script); script.onload = function() { window.ypaAds.insertMultiAd({ ypaPubParams: { query: self.data.kw }, ypaAdConfig: self.data.config, ypaAdTypeTag: self.data.type, ypaAdSlotInfo: [{ ypaAdSlotId: 'top', ypaAdDivId: 'ypaAdWrapper-top', ypaAdWidth: '700', ypaAdHeight: '10', ypaOnNoAd: noadpassback, ypaSlotOptions: { TemplateOptions: { DeskTop: { AdUnit: { cssLink: self.data.style } }, Mobile: { AdUnit: { cssLink: self.data.style } } } } }] }); } } }; window.loadYpa = loadYpa; loadYpa.init(); } )(); //$('.ypaAdAnchor').on("click",function(){ // alert('test'); //});