Jump to content
Sign in to follow this  
Dexter

Detect User Environment

Recommended Posts

Synopsis

 

I made this because I needed this. This snippet gives functions to detect the user's browser or operating system. 

Detectable Browsers are: Google Chrome, Mozilla Firefox, Internet Explorer, Microsoft Edge, and Safari. Detectable Operating systems are Linux, Unix, Windows and Mac

 

How does it work?

 

Detect the browser by calling the function 

Detect.browser()

This function will return one the following as a string:

 "Google Chrome", "Mozilla Firefox", "Internet Explorer", "Microsoft Edge", "Safari"

If you have a browser that you would like added please tell me and a I will add it if deemed necessary.

 

Detect the operating system by calling the function

Detect.OS()

This function will return one of the following as a string:

"Windows", "Mac OS", "Unix", Linux

Code:

Download detect.js

var Detect = {
    browser: function() {
        var n = navigator.userAgent.indexOf(" Edge/") >= 0,
            e = !!window.opera || navigator.userAgent.indexOf(" OPR/") >= 0,
            o = "undefined" != typeof InstallTrigger,
            r = (Object.prototype.toString.call(window.HTMLElement).indexOf("Constructor") > 0, !!window.chrome && !e && !n),
            i = !!document.documentMode;
        return 1 == e ? "Opera" : 1 == o ? "Mozilla Firefox" : 1 == r ? "Google Chrome" : 1 == i ? "Internet Explorer" : 1 == n ? "Microsoft Edge" : void 0
    },
    OS: function() {
        var n = "Unknown OS";
        return -1 != navigator.appVersion.indexOf("Win") && (n = "Windows"), -1 != navigator.appVersion.indexOf("Mac") && (n = "MacOS"), -1 != navigator.appVersion.indexOf("X11") && (n = "UNIX"), -1 != navigator.appVersion.indexOf("Linux") && (n = "Linux"), n
    }
};

I recommend that you place this in the libs/ folder instead of the plugins folder to make the Detect function universal for all plugins.

 

Usage

Feel free to use in commercial or non-commercial credit is appreciated but not necessary.

  • Like 1

Share this post


Link to post
Share on other sites

There was one person.(Rikifive I believe) that was looking for a plug-in that would pause the game BGM when it was minimized.

Would that be possible to do?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted