Skip to content

Instantly share code, notes, and snippets.

@matiaskorhonen
Last active September 24, 2016 11:37
Show Gist options
  • Select an option

  • Save matiaskorhonen/5df9d30dc5c798615cc12860e229b58b to your computer and use it in GitHub Desktop.

Select an option

Save matiaskorhonen/5df9d30dc5c798615cc12860e229b58b to your computer and use it in GitHub Desktop.
Browser and system information. Uses FlashDetect (www.featureblend.com/javascript-flash-detection-library.html) and cookie.js (https://github.com/florian/cookie.js)
// Underscore.js
// http://underscorejs.org
// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.
//
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
//= require cookie
//= require debounce
//= require flash_detect
var systemInfo = debounce(function() {
var info = {};
if (window.screen && window.screen.width && window.screen.height) {
info["sr"] = window.screen.width + "x" + "" + window.screen.height;
}
if (document.documentElement
&& document.documentElement.clientWidth
&& document.documentElement.clientHeight) {
info["vp"] = window.screen.width + "x" + "" + document.documentElement.clientHeight;
}
if (window.screen && window.screen.colorDepth) {
info["sd"] = window.screen.colorDepth + "-bits";
}
var lang = navigator.languages && navigator.languages[0] || // Chrome / Firefox
navigator.language || // All browsers
navigator.userLanguage; // IE <= 10
if (lang) {
info["ul"] = lang;
}
try {
info["je"] = navigator.javaEnabled();
} catch (e) {
info["je"] = false;
}
if (FlashDetect.installed) {
info["fl"] = FlashDetect.major + " " +
FlashDetect.minor + " " +
FlashDetect.revisionStr;
}
try {
var protocol = (window.location.protocol || document.location.protocol);
cookie.set(
{ sysinfo: JSON.stringify(info) },
{ secure: (protocol == "https:"), path: "/" }
);
} catch (e) {}
}, 250);
$(document).on("turbolinks:load", systemInfo)
$(window).on("resize", systemInfo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment