-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from 201flaviosilva-labs/44-get-browser-data
Get browser data
- Loading branch information
Showing
22 changed files
with
249 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Detects and returns the browser name | ||
* | ||
* Function based in ➜ {@link https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser} | ||
* | ||
* @example getBrowser(); // Opera | ||
* @example getBrowser(); // Chrome | ||
* @example getBrowser(); // Safari | ||
* @example getBrowser(); // Firefox | ||
* @example getBrowser(); // IE | ||
* @example getBrowser(); // Unknown // Not detect | ||
* | ||
* @returns {String} browser name | ||
* | ||
* @function getBrowser | ||
* @memberof Device | ||
*/ | ||
export function getBrowser() { | ||
if ((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf("OPR")) != -1) return "Opera"; | ||
else if (navigator.userAgent.indexOf("Chrome") != -1) return "Chrome"; | ||
else if (navigator.userAgent.indexOf("Safari") != -1) return "Safari"; | ||
else if (navigator.userAgent.indexOf("Firefox") != -1) return "Firefox"; | ||
else if (navigator.userAgent.indexOf("MSIE") != -1 || !!document.documentMode == true) return "IE"; | ||
else return "Unknown"; // IF IE > 10 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Detects and returns the browser version | ||
* | ||
* Function based in ➜ {@link https://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser} | ||
* | ||
* @example getBrowserVersion(); // 106 | ||
* @example getBrowserVersion(); // 105 | ||
* | ||
* @returns {Number|String} browser version | ||
* | ||
* @function getBrowserVersion | ||
* @memberof Device | ||
*/ | ||
export function getBrowserVersion() { | ||
const ua = navigator.userAgent; | ||
let tem = null; | ||
let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; | ||
|
||
if (/trident/i.test(M[1])) { | ||
tem = /\brv[ :]+(\d+)/g.exec(ua) || []; | ||
return "IE " + (tem[1] || ""); | ||
} | ||
|
||
if (M[1] === "Chrome") { | ||
tem = ua.match(/\b(OPR|Edge)\/(\d+)/); | ||
if (tem != null) return tem.slice(1).join(" ").replace("OPR", "Opera"); | ||
} | ||
|
||
M = M[2] ? [M[2]] : [navigator.appVersion, "-?"]; // M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, "-?"]; | ||
if ((tem = ua.match(/version\/(\d+)/i)) != null) M.splice(1, 1, tem[1]); | ||
return M; // return M.join(" "); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Detects and returns the Operating System name | ||
* | ||
* Function based in ➜ {@link https://stackoverflow.com/questions/38241480/detect-macos-ios-windows-android-and-linux-os-with-js} | ||
* | ||
* @example getOS(); // Mac OS | ||
* @example getOS(); // Windows | ||
* @example getOS(); // iOS | ||
* @example getOS(); // UNIX | ||
* @example getOS(); // Android | ||
* @example getOS(); // Linux | ||
* @example getOS(); // Unknown // Not detect | ||
* | ||
* @returns {String} Operating System name | ||
* | ||
* @function getOS | ||
* @memberof Device | ||
*/ | ||
export function getOS() { | ||
const userAgent = window.navigator.userAgent; | ||
const platform = window.navigator.platform; | ||
|
||
const macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"]; | ||
const iosPlatforms = ["iPhone", "iPad", "iPod"]; | ||
const windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"]; | ||
const unixPlatforms = ["X11"]; | ||
|
||
if (macosPlatforms.indexOf(platform) !== -1) return "Mac OS"; | ||
else if (iosPlatforms.indexOf(platform) !== -1) return "iOS"; | ||
else if (windowsPlatforms.indexOf(platform) !== -1) return "Windows"; | ||
else if (unixPlatforms.indexOf(userAgent) != -1) return "UNIX"; | ||
else if (/Android/.test(userAgent)) return "Android"; | ||
else if (!os && /Linux/.test(platform)) return "Linux"; | ||
return "Unknown"; | ||
} |
Oops, something went wrong.