Created
March 9, 2020 21:19
-
-
Save shawncrigger/13fdae41abf0045bcd8c96ce93fa2a5a to your computer and use it in GitHub Desktop.
Sets Cookie with useful info like OS, Browser, Version, User Agent, Browser Vendor, Screen Size and View Port Size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
var fetchDebugInfo = { | |
options: [], | |
header: [navigator.platform, navigator.userAgent, navigator.appVersion, navigator.vendor, window.opera], | |
dataos: [ | |
{ name: 'Windows Phone', value: 'Windows Phone', version: 'OS' }, | |
{ name: 'Windows', value: 'Win', version: 'NT' }, | |
{ name: 'iPhone', value: 'iPhone', version: 'OS' }, | |
{ name: 'iPad', value: 'iPad', version: 'OS' }, | |
{ name: 'Kindle', value: 'Silk', version: 'Silk' }, | |
{ name: 'Android', value: 'Android', version: 'Android' }, | |
{ name: 'PlayBook', value: 'PlayBook', version: 'OS' }, | |
{ name: 'BlackBerry', value: 'BlackBerry', version: '/' }, | |
{ name: 'Macintosh', value: 'Mac', version: 'OS X' }, | |
{ name: 'Linux', value: 'Linux', version: 'rv' }, | |
{ name: 'Palm', value: 'Palm', version: 'PalmOS' } | |
], | |
databrowser: [ | |
{ name: 'Chrome', value: 'Chrome', version: 'Chrome' }, | |
{ name: 'Firefox', value: 'Firefox', version: 'Firefox' }, | |
{ name: 'Safari', value: 'Safari', version: 'Version' }, | |
{ name: 'Internet Explorer', value: 'MSIE', version: 'MSIE' }, | |
{ name: 'Opera', value: 'Opera', version: 'Opera' }, | |
{ name: 'BlackBerry', value: 'CLDC', version: 'CLDC' }, | |
{ name: 'Mozilla', value: 'Mozilla', version: 'Mozilla' } | |
], | |
init: function () { | |
var agent = this.header.join(' '), | |
os = this.matchItem(agent, this.dataos), | |
browser = this.matchItem(agent, this.databrowser); | |
return { os: os, browser: browser }; | |
}, | |
refresh: function () { | |
e = this.init(); | |
var values = { "name" : e.os.name,"version" : e.os.version,"browserName" : e.browser.name,"browserVersion" : e.browser.version,"userAgent" : navigator.userAgent,"appVersion": navigator.appVersion, "platform" : navigator.platform, "vendor": navigator.vendor, "viewportWidth": window.innerWidth, "viewportHeight": window.innerHeight, "screenWidth": screen.width, "screenHeight": screen.height, "cookies": navigator.cookieEnabled ? "Available" : "Unavailable" } | |
values = JSON.stringify(e.values); | |
Cookies.set('FC_debug_info', values, { expires: 7, path: '' }); | |
}, | |
matchItem: function (string, data) { | |
var i = 0, | |
j = 0, | |
html = '', | |
regex, | |
regexv, | |
match, | |
matches, | |
version; | |
for (i = 0; i < data.length; i += 1) { | |
regex = new RegExp(data[i].value, 'i'); | |
match = regex.test(string); | |
if (match) { | |
regexv = new RegExp(data[i].version + '[- /:;]([\\d._]+)', 'i'); | |
matches = string.match(regexv); | |
version = ''; | |
if (matches) { if (matches[1]) { matches = matches[1]; } } | |
if (matches) { | |
matches = matches.split(/[._]+/); | |
for (j = 0; j < matches.length; j += 1) { | |
if (j === 0) { | |
version += matches[j] + '.'; | |
} else { | |
version += matches[j]; | |
} | |
} | |
} else { | |
version = '0'; | |
} | |
return { | |
name: data[i].name, | |
version: parseFloat(version) | |
}; | |
} | |
} | |
return { name: 'unknown', version: 0 }; | |
} | |
}; | |
var e = fetchDebugInfo.refresh(); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment