Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luislobo14rap/2d080110d2b8dee5b4acc37ca11f0a32 to your computer and use it in GitHub Desktop.
Save luislobo14rap/2d080110d2b8dee5b4acc37ca11f0a32 to your computer and use it in GitHub Desktop.
is.js (only for detect chrome in mac and ios).js
/*!
* is.js 0.9.0
* Author: Aras Atasaygin. Adapted by Luis Lobo
*/
// define 'is' object and current version
let is = {};
is.VERSION = '0.9.0';
// store navigator properties to use later
let navigator = window.navigator || {};
let platform = (navigator.platform || '').toLowerCase();
let userAgent = (navigator.userAgent || '').toLowerCase();
let vendor = (navigator.vendor || '').toLowerCase();
// is current browser opera?
// parameter is optional
is.opera = function(range) {
let match = userAgent.match(/(?:^opera.+?version|opr)\/(\d+)/);
return match !== null /* && compareVersion(match[1], range) */;
};
// is current browser chrome?
// parameter is optional
is.chrome = function(range) {
let match = /google inc/.test(vendor) ? userAgent.match(/(?:chrome|crios)\/(\d+)/) : null;
return match !== null && !is.opera() /* && compareVersion(match[1], range) */;
};
// is current device iphone?
// parameter is optional
is.iphone = function(range) {
// avoid false positive for Facebook in-app browser on ipad;
// original iphone doesn't have the OS portion of the UA
let match = is.ipad() ? null : userAgent.match(/iphone(?:.+?os (\d+))?/);
return match !== null /* && compareVersion(match[1] || 1, range) */;
};
// is current device ipad?
// parameter is optional
is.ipad = function(range) {
let match = userAgent.match(/ipad.+?os (\d+)/);
return match !== null /* && compareVersion(match[1], range) */;
};
// is current device ipod?
// parameter is optional
is.ipod = function(range) {
let match = userAgent.match(/ipod.+?os (\d+)/);
return match !== null /* && compareVersion(match[1], range) */;
};
// is current device ios?
is.ios = function() {
return is.iphone() || is.ipad() || is.ipod();
};
// is current operating system mac?
is.mac = function() {
return /mac/.test(platform);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment