/*
	BrowserGet.js - Browser detection function
	2020 by mercury0x0d, Creative Commons Attribution 4.0 International License

	Revision history:
	2020-04-26 - Added licensing
	2020-03-16 - Initial release
*/





const browserUnknown = 0, browserChrome = 1, browserChromium = 2, browserEdge = 4, browserIE = 8, browserSafari = 16, browserOpera = 32, browserFirefox = 64;

function BrowserGet()
{
	var nav = window.navigator;
	var vendor = nav.vendor;
	var theUA = nav.userAgent;


	// an easier way to do this would be .includes, however .indexOf is used to maximize compatibility with older / more obscure browsers

	// probe the User Agent string
	var foundChrome = theUA.indexOf('Chrome');
	var foundChromium = theUA.indexOf('Chromium');
	var foundEdge = theUA.indexOf('Edg');
	var foundFirefox = theUA.indexOf('Firefox');
	var foundIE = theUA.indexOf('Trident');
	var foundOpera = theUA.indexOf('OPR');

	// probe the Vendor string
	var foundSafari = vendor.indexOf('Apple Computer, Inc.');

console.log('|' + foundChrome + '|' + foundChromium + '|' + foundEdge + '|' + foundFirefox + '|' + foundIE + '|' + foundOpera + '|' + foundSafari + '|');

	// return some info!
	if (foundOpera != -1) return browserOpera;

	if (foundSafari != -1) return browserSafari;

	if (foundIE != -1) return browserIE;

	if (foundEdge != -1) return browserEdge;

	if (foundFirefox != -1 && foundChrome == -1 && foundChromium == -1 && foundSafari == -1 && foundOpera == -1) return browserFirefox;

	if (vendor.indexOf('Google Inc.') > -1)
	{
		if (foundChrome != 0 && foundChromium == -1) return browserChrome;
		if (foundChrome != 0 && foundChromium) return browserChromium;
	}

	return browserUnknown;
}
