function AdvertHelper(kind) { function isWeiXin(){ var ua = window.navigator.userAgent.toLowerCase(); return ua.match(/MicroMessenger/i) == 'micromessenger'; } var ShowAd = !isWeiXin(); var thisObj = this; this.link = "https://live.8bo8.com/redirect/?id="; this.items = new Object(); this.getItem = function (name, defaultValue) { if (typeof (defaultValue) == "undefined") defaultValue = []; var arr = this.items[name]; if (!arr) return defaultValue; else return arr; } function getAdvUrl(id) { return thisObj.link+id; } this.setArrEach = function (idName, onefunc) { var json = this.items; if (!!json[idName]) { var tempObj = json[idName]; for (var i = 0; i < tempObj.length; i++) { var oneTemp = tempObj[i]; setHtml(idName + "[" + i + "]", onefunc(oneTemp, getAdvUrl(oneTemp.id), i)); } } } this.setEach = function (idName, onefunc, dividedStr) { var html = this.getEach(idName, onefunc, dividedStr); if (!!html) setHtml(idName, html); } this.getEach = function (idName, onefunc, dividedStr) { var json = this.items; if (typeof (dividedStr) == "undefined") dividedStr = ""; if (!!json[idName]) { var tempObj = json[idName]; var htmlArr = new Array(); for (var i = 0; i < tempObj.length; i++) { var oneTemp = tempObj[i]; htmlArr.push(onefunc(oneTemp)); } return htmlArr.join(dividedStr); } else return ""; } if (window.location.href.indexOf("my=ad") > 0) ShowAd = true; function setHtml(idName, html) { var dom = document.getElementById(idName); if (!!dom) dom.innerHTML = html; } var funcObj; AdvertHelper.callBack = function (json) { if (!!json) thisObj.items = json; if (typeof funcObj == "object") for (var key in funcObj) { thisObj.setArrEach(key, funcObj); } else if (typeof funcObj === "function") funcObj(); } this.init = function (func) { if (ShowAd) { funcObj = func; jQuery.ajax({ type: "get", async: true, url: "/live/data/getAd.js", //data: { 'fromID': '3', 'kind': kind }, dataType: "jsonp", jsonp: "callback", jsonpCallback: "AdvertHelper.callBack", success: function (json) { AdvertHelper.callBack(json); }, error: function () { } }); } } }