$(function() { var device = {}; var nav = _.clone(window.navigator); nav.plugins = _.map(navigator.plugins, function(obj, key) { return obj.name + ' (' + obj.filename + ')'; }); //device.navigator = _.omit(nav, [ // 'appCodeName', // 'appMinorVersion', // 'appName', // 'appVersion', // 'battery', // 'cpuClass', // 'geolocation', // 'mimeTypes', // 'oscpu', // 'platform', // 'product', // 'vendor', // 'vendorSub' //]); device.navigator = _.pick(nav, [ 'cookieEnabled', 'doNotTrack', 'hardwareConcurrency', 'language', 'languages', 'maxTouchPoints', 'onLine', 'plugins', 'productSub', 'browserLanguage', 'systemLanguage', 'userLanguage', 'userAgent' ]); device.screen = _.pick(window.screen, [ "availHeight", "availLeft", "availTop", "availWidth", "colorDepth", "height", "pixelDepth", "width" ]); device.screen.body = _.pick(document.body, 'clientWidth', 'clientHeight', 'offsetWidth', 'offsetHeight', 'scrollWidth', 'scrollHeight'); device.screen.pixelRatio = window.devicePixelRatio; var orientation = window.screen.orientation || window.screen.mozOrientation || window.screen.msOrientation; if(!_.isString(orientation)) orientation = _.pick(orientation, [ 'type', 'angle' ]); device.screen.orientation = orientation; device.modernizr = _.compact($(document.documentElement).attr('class').split(' ')); //nav.javaEnabled = nav.javaEnabled(); var $div = $('#content'); _.each(device, function(value, key) { $div.append($('
');
$pre.text(JSON.stringify(value, null, 2));
$div.append($pre);
});
// TODO maybe have server send Headers from AJAX request
var id = window.location.search ? window.location.search.split('=')[1] : 'null';
var path = window.location.protocol + '//' + window.location.host + '/api/fingerprints/' + id;
console.log(path);
$.ajax({
method: 'POST',
dataType: 'json',
data: device,
url: path,
success: function(res) {
var key = 'headers';
$div.append($('' + key + '
'));
var $pre = $('');
$pre.text(JSON.stringify(res.headers, null, 2));
$div.append($pre);
console.log('success');
},
error: function() {
console.log('error');
}
});
});