Skip to content

Instantly share code, notes, and snippets.

@alterebro
Created September 30, 2016 13:56
Show Gist options
  • Save alterebro/b8ba40ea0dd419a04041cb1b311648a4 to your computer and use it in GitHub Desktop.
Save alterebro/b8ba40ea0dd419a04041cb1b311648a4 to your computer and use it in GitHub Desktop.
Detect Opera Browser and the 'Extreme Savings' mode from the mobile Opera Mini web browser
// Setup operaDetect object
var operaDetect = new Object;
// Check if current browser is Opera
operaDetect.isOpera = !!window.opera |
!!window.opr |
( navigator.userAgent.indexOf(' OPR/') > -1 ) |
( navigator.userAgent.indexOf(' Coast/') > -1 ) |
( navigator.userAgent.indexOf(' OPiOS/') > -1 );
// IF CURRENT BROWSER IS AN OPERA BROWSER
if ( operaDetect.isOpera ) {
operaDetect.results = new Object;
/* Platform */
if ( (navigator.userAgent.indexOf('Mobile') > -1) |
(navigator.userAgent.indexOf('Opera Mini/') > -1) ) {
operaDetect.results.platform = "Mobile/Tablet";
} else if ( navigator.userAgent.indexOf('OMI/') > -1 ) {
operaDetect.results.platform = "TV";
} else {
operaDetect.results.platform = "Desktop";
}
/* OS */
if ( navigator.userAgent.indexOf('Android') > -1 ) {
operaDetect.results.OS = "Android";
} else if ( (navigator.userAgent.indexOf('Coast/') > -1) |
(navigator.userAgent.indexOf('iPad') > -1) |
(navigator.userAgent.indexOf('iPhone') > -1) ) {
operaDetect.results.OS = "iOS";
} else if ( (navigator.userAgent.indexOf('OS X') > -1) ) {
operaDetect.results.OS = "OSX";
} else if ( (navigator.userAgent.indexOf('Windows') > -1) ) {
operaDetect.results.OS = "Windows";
} else {
operaDetect.results.OS = "Other";
}
/* Browser */
if ( (navigator.userAgent.indexOf('OPiOS/') > -1) |
(navigator.userAgent.indexOf('Opera Mini/') > -1) |
(/OPR\/[0-9]+/.test(navigator.userAgent) > -1 && navigator.userAgent.indexOf('Mobile') > -1) ) {
operaDetect.results.browser = "Opera Mini";
} else if ( navigator.userAgent.indexOf('OPR/') > -1 &&
navigator.userAgent.indexOf('Mobile') > -1 ) {
operaDetect.results.browser = "Opera Mobile";
} else if ( (navigator.userAgent.indexOf('Coast/') > -1) ) {
operaDetect.results.browser = "Opera Coast";
} else if ( (navigator.userAgent.indexOf('OPR/') > -1) ) {
operaDetect.results.browser = "Opera Desktop";
} else {
operaDetect.results.browser = "Unknown";
}
/* Mode */
if ( (navigator.userAgent.indexOf('Presto/') > -1) &&
(navigator.userAgent.indexOf('Opera Mini/') > -1) ) {
operaDetect.results.mode = "Extreme Savings";
operaDetect.isExtremeMode = 1;
} else {
operaDetect.results.mode = "High/Normal Savings";
operaDetect.isExtremeMode = 0;
}
} else {
// IF CURRENT BROWSER IS NOT OPERA BROWSER
operaDetect.results = 0;
operaDetect.isExtremeMode = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment