forked from codejoust/session.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.min.js
1 lines (1 loc) · 9.03 KB
/
session.min.js
1
var session_fetch=function(a,b,c){"use strict";var d=.4,e={use_html5_location:!1,ipinfodb_key:!1,gapi_location:!0,location_cookie:"location",location_cookie_timeout:5,session_timeout:32,session_cookie:"first_session",get_object:null,set_object:null},f=function(){if(a.session=a.session||{},a.session.contains=function(a){if("string"==typeof a)return this.indexOf(a)!==-1;for(var b=0;b<a.length;b++)if(this.indexOf(a[b])!==-1)return!0;return!1},a.session&&a.session.options)for(var b in a.session.options)e[b]=a.session.options[b];var c={api_version:d,locale:h.locale(),current_session:h.session(),original_session:h.session(e.session_cookie,24*e.session_timeout*60*60*1e3),browser:h.browser(),plugins:h.plugins(),time:h.time(),device:h.device()};if(e.use_html5_location?c.location=h.html5_location():e.ipinfodb_key?c.location=h.ipinfodb_location(e.ipinfodb_key):e.gapi_location&&(c.location=h.gapi_location()),a.session&&a.session.start)var f=a.session.start;var i,g=0,k=function(b){b&&g--,0===g&&f&&f(a.session)};a.session={};for(var l in c)if(i=c[l],"function"==typeof i)try{i(function(b){a.session[l]=b,k(!0)}),g++}catch(b){a.console&&"function"==typeof console.log&&(console.log(b),k(!0))}else a.session[l]=i;k()},g={detect:function(){var a={browser:this.search(this.data.browser),version:this.search(c.userAgent)||this.search(c.appVersion),os:this.search(this.data.os)};if("Linux"==a.os)for(var b=["CentOS","Debian","Fedora","Gentoo","Mandriva","Mageia","Red Hat","Slackware","SUSE","Turbolinux","Ubuntu"],d=0;d<b.length;d++)if(c.userAgent.toLowerCase().match(b[d].toLowerCase())){a.distro=b[d];break}return a},search:function(a){if("object"!=typeof a){var e=a.indexOf(this.version_string);if(e==-1)return;return parseFloat(a.substr(e+this.version_string.length+1))}for(var b=0;b<a.length;b++){var c=a[b].string,d=a[b].prop;if(this.version_string=a[b].versionSearch||a[b].identity,c){if(c.indexOf(a[b].subString)!=-1)return a[b].identity}else if(d)return a[b].identity}},data:{browser:[{string:c.userAgent,subString:"Edge",identity:"Edge"},{string:c.userAgent,subString:"Chrome",identity:"Chrome"},{string:c.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"OmniWeb"},{string:c.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{prop:a.opera,identity:"Opera",versionSearch:"Version"},{string:c.vendor,subString:"iCab",identity:"iCab"},{string:c.vendor,subString:"KDE",identity:"Konqueror"},{string:c.userAgent,subString:"Firefox",identity:"Firefox"},{string:c.vendor,subString:"Camino",identity:"Camino"},{string:c.userAgent,subString:"Netscape",identity:"Netscape"},{string:c.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"},{string:c.userAgent,subString:"Trident",identity:"Explorer",versionSearch:"rv"},{string:c.userAgent,subString:"Gecko",identity:"Mozilla",versionSearch:"rv"},{string:c.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}],os:[{string:c.platform,subString:"Win",identity:"Windows"},{string:c.platform,subString:"Mac",identity:"Mac"},{string:c.userAgent,subString:"iPhone",identity:"iPhone/iPod"},{string:c.userAgent,subString:"iPad",identity:"iPad"},{string:c.userAgent,subString:"Android",identity:"Android"},{string:c.platform,subString:"Linux",identity:"Linux"}]}},h={browser:function(){return g.detect()},time:function(){var a=new Date,b=new Date;return a.setMonth(0),a.setDate(1),b.setMonth(6),b.setDate(1),{tz_offset:-(new Date).getTimezoneOffset()/60,observes_dst:a.getTimezoneOffset()!==b.getTimezoneOffset()}},locale:function(){var a=(c.language||c.browserLanguage||c.systemLanguage||c.userLanguage||"").split("-");return 2==a.length?{country:a[1].toLowerCase(),lang:a[0].toLowerCase()}:a?{lang:a[0].toLowerCase(),country:null}:{lang:null,country:null}},device:function(){var e,f,d={screen:{width:a.screen.width,height:a.screen.height}};try{e=a.innerWidth||b.documentElement.clientWidth||b.body.clientWidth}catch(a){e=0}try{f=a.innerHeight||b.documentElement.clientHeight||b.body.clientHeight}catch(a){f=0}return d.viewport={width:e,height:f},d.is_tablet=!!c.userAgent.match(/(iPad|SCH-I800|xoom|kindle)/i),d.is_phone=!d.is_tablet&&!!c.userAgent.match(/(iPhone|iPod|blackberry|android|htc|lg|midp|mmp|mobile|nokia|opera mini|palm|pocket|psp|sgh|smartphone|symbian|treo mini|Playstation Portable|SonyEricsson|Samsung|MobileExplorer|PalmSource|Benq|Windows Phone|Windows Mobile|IEMobile|Windows CE|Nintendo Wii)/i),d.is_mobile=d.is_tablet||d.is_phone,d},plugins:function(){var a=function(a){if(c.plugins){for(var b,d=0,e=c.plugins.length;d<e;d++)if(b=c.plugins[d],b&&b.name&&b.name.toLowerCase().indexOf(a)!==-1)return!0;return!1}return!1},b=function(a){for(var b=!0,c=0;c<a.length;c++){try{var b=(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"+a[c]),!0)}catch(a){}if(b)return!0}return!1};return{flash:a("flash")||b([".7",".6",""]),silverlight:a("silverlight"),java:a("java"),quicktime:a("quicktime")}},session:function(c,d){var e=i.get_obj(c);if(null==e){e={visits:1,start:(new Date).getTime(),last_visit:(new Date).getTime(),url:a.location.href,path:a.location.pathname,referrer:b.referrer,referrer_info:i.parse_url(b.referrer),search:{engine:null,query:null}};var h,f=[{name:"Google",host:"google",query:"q"},{name:"Bing",host:"bing.com",query:"q"},{name:"Yahoo",host:"search.yahoo",query:"p"},{name:"AOL",host:"search.aol",query:"q"},{name:"Ask",host:"ask.com",query:"q"},{name:"Baidu",host:"baidu.com",query:"wd"}],g=f.length,k=0,l="q query term p wd query text".split(" ");for(k=0;k<g;k++)if(h=f[k],e.referrer_info.host.indexOf(h.host)!==-1){e.search.engine=h.name,e.search.query=e.referrer_info.query[h.query],e.search.terms=e.search.query?e.search.query.split(" "):null;break}if(null===e.search.engine&&e.referrer_info.search.length>1)for(k=0;k<l.length;k++){var m=e.referrer_info.query[l[k]];if(m){e.search.engine="Unknown",e.search.query=m,e.search.terms=m.split(" ");break}}}else e.prev_visit=e.last_visit,e.last_visit=(new Date).getTime(),e.visits++,e.time_since_last_visit=e.last_visit-e.prev_visit;return i.set_obj(c,e,d),e},html5_location:function(){return function(a){c.geolocation.getCurrentPosition(function(b){b.source="html5",a(b)},function(b){e.gapi_location?h.gapi_location()(a):a({error:!0,source:"html5"})})}},gapi_location:function(){return function(b){var c=i.get_obj(e.location_cookie);c&&"google"===c.source?b(c):(a.gloader_ready=function(){"google"in a&&(a.google.loader.ClientLocation?(a.google.loader.ClientLocation.source="google",b(a.google.loader.ClientLocation)):b({error:!0,source:"google"}),i.set_obj(e.location_cookie,a.google.loader.ClientLocation,60*e.location_cookie_timeout*60*1e3))},i.embed_script("https://www.google.com/jsapi?callback=gloader_ready"))}},architecture:function(){var a=n.userAgent.match(/x86_64|Win64|WOW64|x86-64|x64\;|AMD64|amd64/)||"x64"===n.cpuClass?"x64":"x86";return{arch:a,is_x64:"x64"==a,is_x86:"x68"==a}},ipinfodb_location:function(b){return function(c){var d=i.get_obj(e.location_cookie);d||"ipinfodb"!==d.source?c(d):(a.ipinfocb=function(a){if("OK"===a.statusCode)a.source="ipinfodb",i.set_obj(e.location_cookie,a,60*e.location_cookie*60*1e3),c(a);else{if(e.gapi_location)return h.gapi_location()(c);c({error:!0,source:"ipinfodb",message:a.statusMessage})}},i.embed_script("http://api.ipinfodb.com/v3/ip-city/?key="+b+"&format=json&callback=ipinfocb"))}}},i={parse_url:function(a){var c=b.createElement("a"),d={};c.href=a;var e=c.search.substr(1);if(""!=e)for(var i,f=e.split("&"),g=0,h=f.length;g<h;g++)i=f[g].split("="),2===i.length&&(d[i[0]]=decodeURI(i[1]));return{host:c.host,path:c.pathname,protocol:c.protocol,port:""===c.port?80:c.port,search:c.search,query:d}},set_cookie:function(c,d,e,f){return c?(f||(f={}),null!==d&&void 0!==d||(e=-1),e&&(f.expires=(new Date).getTime()+e),b.cookie=[encodeURIComponent(c),"=",encodeURIComponent(String(d)),f.expires?"; expires="+new Date(f.expires).toUTCString():"","; path="+(f.path?f.path:"/"),f.domain?"; domain="+f.domain:"",a.location&&"https:"===a.location.protocol?"; secure":""].join("")):null},get_cookie:function(a,c){return(c=new RegExp("(?:^|; )"+encodeURIComponent(a)+"=([^;]*)").exec(b.cookie))?decodeURIComponent(c[1]):null},embed_script:function(a){var c=b.createElement("script");c.type="text/javascript",c.src=a,(b.body||b.getElementsByTagName("body")[0]||b.head).appendChild(c)},package_obj:function(a){if(a){a.version=d;var b=j.stringify(a);return delete a.version,b}},set_obj:function(a,b,c,d){i.set_cookie(a,i.package_obj(b),c,d)},get_obj:function(a){var b;try{b=j.parse(i.get_cookie(a))}catch(a){}if(b&&b.version==d)return delete b.version,b}};null!=e.get_object&&(i.get_obj=e.get_object),null!=e.set_object&&(i.set_obj=e.set_object);var j={parse:a.JSON&&a.JSON.parse||function(a){return"string"==typeof a&&a?new Function("return "+a)():null},stringify:a.JSON&&a.JSON.stringify||function(a){var b=typeof a;if("object"===b&&null!==a){var c,d,e=[],f=a&&a.constructor===Array;for(c in a)d=a[c],b=typeof d,"string"===b?d='"'+d+'"':"object"===b&&null!==d&&(d=this.stringify(d)),e.push((f?"":'"'+c+'":')+d);return(f?"[":"{")+e.join(",")+(f?"]":"}")}if("string"===b)return'"'+a+'"'}};f()};"undefined"==typeof window.exports?session_fetch(window,document,navigator):window.exports.session=session_fetch;