-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathppo.min.js
1 lines (1 loc) · 7.67 KB
/
ppo.min.js
1
!function(e,o){"function"==typeof define&&define.amd?define([],o):"undefined"!=typeof module&&module.exports?module.exports=o():e.ppo=o()}(this,function(){function ppo(){}ppo.isIOS=ppo.isIos=function(){return/iPad|iPhone|iPod/.test(ppo.ua())},ppo.isIPad=function(){return/iPad/.test(ppo.ua())},ppo.isAndroid=function(){return-1<ppo.ua("l").indexOf("android")},ppo.isMobile=function(){return/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(ppo.ua("l"))},ppo.isPC=function(){return!this.isMobile()},ppo.isWeixin=function(){return/MicroMessenger/i.test(ppo.ua("l"))},ppo.isIE=function(){return 0<ppo.ieVer()},ppo.ieVersion=ppo.ieVer=function(){var e=ppo.ua(),o=e.indexOf("MSIE ");return 0<o?parseInt(e.substring(o+5,e.indexOf(".",o)),10):0<e.indexOf("Trident/")?(o=e.indexOf("rv:"),parseInt(e.substring(o+3,e.indexOf(".",o)),10)):0<(o=e.indexOf("Edge/"))?parseInt(e.substring(o+5,e.indexOf(".",o)),10):-1},ppo.ua=function(e){return e?window.navigator.userAgent.toLowerCase():window.navigator.userAgent},ppo.log=function(e,o){var t=document.getElementById("_ppo_log");if(null===t&&((t=document.createElement("div")).setAttribute("id","_ppo_log"),t.setAttribute("style","position:fixed;left:0;top:0;z-index:9999;padding:4px;"),document.body.appendChild(t)),o)for(var n in o)t.style[n]=o[n];t.innerHTML=e},ppo.logs=function(){var e,o,t;window.console&&window.console.log&&(e=arguments[0]+"",o=parseInt(e.split("&")[1])||10,(t=ppo._cache.logs)[e]||(t[e]={}),t[e].once||(t[e].once=1),t[e].once<=o)&&(console.log.apply(console,ppo.args(arguments,1)),t[e].once++)},ppo.removeConsole=function(e){try{window.console||(window.console={}),window.console.log=window.console.info=window.console.dir=window.console.warn=window.console.trace=ppo.noop,"clear"===e&&window.console.clear&&window.console.clear()}catch(e){}},ppo.open=function(e){var o="_ppo_open_proxy",t=document.getElementById(o)||document.createElement("a");t.setAttribute("id",o),t.setAttribute("href",e),t.setAttribute("target","_blank"),t.style.display="none",t.parentNode||document.body.appendChild(t),this.trigger(t,"click","MouseEvents")},ppo.trigger=function(e,o,t){var n;if(document.createEventObject)return n=document.createEventObject(),e.fireEvent("on"+o,n);(n=document.createEvent(t||"HTMLEvents")).initEvent(o,!0,!0),e.dispatchEvent(n)},ppo.setTimesout=function(){var e=arguments[0],o=void 0===arguments[1]?0:parseFloat(arguments[1]),t=void 0===arguments[2]?1:parseInt(arguments[2]),n=3<arguments.length?ppo.args(arguments,3):null,r={index:0,times:t,over:!1},p=setInterval(function(){r.index++,t<r.index?clearInterval(p):(r.index==t&&(r.over=!0),e.apply(r,n))},o);return p},ppo.clearTimesout=function(e){clearInterval(e)},ppo.construct=function(){return new(Function.prototype.bind.apply(arguments[0],arguments))},ppo.paramsName=function(e){return/\(\s*([\s\S]*?)\s*\)/.exec(e.toString())[1].split(/\s*,\s*/)},ppo.getDate=function(e,o){var t=new Date,n=t.getDate(),r=t.getMonth()+1,p=t.getFullYear(),i=t.getHours(),a=t.getMinutes(),t=t.getSeconds(),n=ppo.fill0(n);return p+(e=e||"/")+ppo.fill0(r)+e+n+" "+ppo.fill0(i)+(o=o||":")+ppo.fill0(a)+o+ppo.fill0(t)},ppo.getUrlParam=function(e,o){o=o||window.location.href,e=e.replace(/[\[\]]/g,"\\$&");e=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(o);return e?e[2]?decodeURIComponent(e[2].replace(/\+/g," ")):"":null},ppo.setUrlParam=function(e,o,t){t=t||window.location.href;var n,r=new RegExp("([?|&])"+e+"=.*?(&|#|$)","i");return t.match(r)?t.replace(r,"$1"+e+"="+encodeURIComponent(o)+"$2"):(r="",-1!==t.indexOf("#")&&(r=t.replace(/.*#/,"#"),t=t.replace(/#.*/,"")),n=-1!==t.indexOf("?")?"&":"?",t+n+e+"="+encodeURIComponent(o)+r)},ppo.deleteUrlParam=ppo.delUrlParam=function(e,o){var t=(o=o||window.location.href).split("?");if(2<=t.length){for(var n=encodeURIComponent(e)+"=",r=t[1].split(/[&;]/g),p=r.length;0<p--;)-1!==r[p].lastIndexOf(n,0)&&r.splice(p,1);return o=t[0]+(0<r.length?"?"+r.join("&"):"")}return o},ppo.setCookie=function(e,o,t){var n,r,o=t&&t.raw?o:encodeURIComponent(o),e=encodeURIComponent(e)+"="+o;t&&((t.days?(n=new Date,r=24*t.days*3600*1e3,n):t.hour?(n=new Date,r=3600*t.hour*1e3,n):(r=31536e7,n=new Date)).setTime(n.getTime()+r),e+="; expires="+n.toGMTString(),t.path&&(e+="; path="+t.path),t.domain&&(e+="; domain="+t.domain),t.secure)&&(e+="; true"),document.cookie=e},ppo.getCookie=function(e){for(var o=encodeURIComponent(e)+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var r=t[n];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(o))return decodeURIComponent(r.substring(o.length,r.length))}return null},ppo.deleteCookie=ppo.delCookie=function(e){this.setCookie(e,"",{hour:-1})},ppo.randomColor=function(){return"#"+("00000"+(16777216*Math.random()<<0).toString(16)).slice(-6)},ppo.randomFromArray=ppo.randomfArr=function(e){return e[Math.floor(Math.random()*e.length)]},ppo.randomFromA2B=ppo.randomA2B=function(e,o,t){o=Math.random()*(o-e)+e;return t?Math.floor(o):o},ppo.randomKey=function(e){var o="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";e=e||6;for(var n=0;n<e;n++)o+=t.charAt(Math.floor(Math.random()*t.length));return o},ppo.floor=function(e,o){return o=o||0,Math.floor(e*Math.pow(10,o))/Math.pow(10,o)},ppo.fill0=function(e){return(e=parseFloat(e))<10?"0"+e:e},ppo.currency=function(e){return m=m||0,Math.floor(n*Math.pow(10,m))/Math.pow(10,m)},ppo.lockTouch=function(){function o(e,o){return e.target.tagName!=o.toUpperCase()&&e.target.tagName!=o.toLowerCase()}function e(e){o(e,"input")&&o(e,"textarea")&&o(e,"select")&&o(e,"menus")&&e.preventDefault()}document.addEventListener("touchmove",function(e){e.preventDefault()},!1),document.addEventListener("touchstart",e,!1),document.addEventListener("touchend",e,!1)},ppo.loadjs=function(e,o,t){var n,r="function"==typeof o?(n=this.hash(e+"")+"",o):void 0===o?(n=this.hash(e+"")+"",null):(n=o+"",t);ppo._cache.urls[n]?r&&r():("string"==typeof e?_insertScript:_insertScripts).call(this,e,function(){ppo._cache.urls[n]=!0,r&&r()})},ppo.uuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var o=16*Math.random()|0;return("x"==e?o:3&o|8).toString(16)})},ppo.hash=function(e){e+="";var o,t=0;if(0!==e.length)for(o=0;o<e.length;o++)t=(t<<5)-t+e.charCodeAt(o),t|=0;return t},ppo.judge=ppo.judgment=function(e,o,t){if(this.isTypeof(o,"array"))for(var n in o)if(t){if(e===o[n])return!0}else if(e==o[n])return!0;return!1},ppo.isTypeof=function(e,o){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()===o},ppo.toJSON=ppo.tojson=ppo.toJson=function(res){if(!res)return null;if("string"!=typeof res)return this.isTypeof(res.json,"function")?res.json():res;try{return JSON.parse(res)}catch(e){return eval("("+res+")")}},ppo.toArray=function(e,o){return e?ppo.isTypeof(e,"array")?e:ppo.isTypeof(e,"string")&&0<e.indexOf(",")?e.split(","):o&&ppo.isTypeof(e,"string")?e.split(o):[e]:null},ppo.args=function(e,o){return Array.prototype.slice.call(e,o||0)},ppo.delLastComma=ppo.deleteLastComma=function(e){return e=","===(e+="").slice(e.length-1)?e.slice(0,-1):e},ppo.trash={clear:function(){for(var e in ppo.trash)"log"!==e&&"clear"!==e&&delete ppo.trash[e]},log:function(){for(var e in ppo.trash)"log"!==e&&"clear"!==e&&console.log("ppo.trash:: ",e,ppo.trash[e])}},ppo.noop=function(){},ppo._cache={urls:{},logs:{}};var _insertScripts=function(e,o){for(var t=0;t<e.length;t++)_insertScript(e[t],r);var n=0;function r(){++n>=e.length&&o&&o()}},_insertScript=function(e,o){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src",e),document.getElementsByTagName("head")[0].appendChild(t),/msie/.test(ppo.ua("l"))?t.onreadystatechange=function(){"loaded"!=this.readyState&&"complete"!=this.readyState||o()}:/gecko/.test(ppo.ua("l"))?t.onload=function(){o()}:setTimeout(function(){o()},50)};return ppo});