Permalink
Browse files

1. Added support for Firefox 3.6, Windows Vista, iPad, BlackBerry and…

… Android.

2. Changed J2ME device selector from "mobile" to "j2me"
3. Appended the generic selector "mobile" to all applicable mobile devices (J2ME, BlackBerry, iPhone, iPod)
1 parent 0946776 commit 1d3c1514342a1dfd34961ca3871312d40359bb8a @rafaelp committed Nov 2, 2010
Showing with 21 additions and 18 deletions.
  1. +2 −2 css_browser_selector.js
  2. +19 −16 tests/tester.html
@@ -1,8 +1,8 @@
/*
-CSS Browser Selector v0.3.5 (Feb 05, 2010)
+CSS Browser Selector v0.4.0 (Nov 02, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
-function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
+function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
View
@@ -26,13 +26,14 @@
["Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13", "webkit chrome win"],
["Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13", "webkit chrome win"],
// Firefox
+ ["mozilla/5.0 (macintosh; u; intel mac os x 10.6; en-us; rv:1.9.2.3) gecko/20100401 firefox/3.6.3 gtb7.0", "gecko ff3 ff3_6 mac"], //firefox 3.6 mac
["mozilla/5.0 (macintosh; u; intel mac os x 10.5; en-gb; rv:1.9.1) gecko/20090624 firefox/3.5" , "gecko ff3 ff3_5 mac"], // firefox 3.5 mac
["Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" , "gecko ff2 mac"], // firefox 2 mac
["Mozilla/5.0 (X11; U; Darwin Power Macintosh; en-US; rv:1.8.0.12) Gecko/20070803 Firefox/1.5.0.12 Fink Community Edition" , "gecko mac"], // firefox 1.5 darwin
["Mozilla/5.0 (Windows; u; Windows NT 5.1; en-us; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1" , "gecko ff3 win"], // firefox 3 win
- ["Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9a7) Gecko/2007080210 GranParadiso/3.0a7" , "gecko win"], // firefox dev
+ ["Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9a7) Gecko/2007080210 GranParadiso/3.0a7" , "gecko win vista"], // firefox dev
["Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b2pre) Gecko/2007120505 Minefield/3.0b2pre" , "gecko win"], // firefox dev
- ["Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11" , "gecko ff2 win"], // firefox 2 vista
+ ["Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11" , "gecko ff2 win vista"], // firefox 2 vista
["Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.13) Gecko/20060410 Firefox/1.0.8" , "gecko win"], // firefox 1 xp
["Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.3) Gecko/20041002 Firefox/0.10.1" , "gecko win"], // firefox pre v1
["Mozilla/5.0 (X11; U; SunOS sun4m; en-US; rv:1.4b) Gecko/20030517 Mozilla Firebird/0.6" , "gecko linux"], // firefox firebird
@@ -74,8 +75,8 @@
// Opera
["opera/9.80 (x11; linux i686; u; en) presto/2.2.15 version/10.01" , "opera opera10 linux"], // Opera 10.01
["Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.2.15 Version/10.10" , "opera opera10 linux"], // Opera 10.10
- ["opera/9.80 (windows nt 6.0; u; en) presto/2.2.15 version/10.00" , "opera opera10 win"], // Opera 10
- ["opera/9.50 (j2me/midp; opera mini/ 4.1.11320/546; u; pt)" , "opera opera9 mobile"], // Opera Mini 10.00 on MAC with OS X
+ ["opera/9.80 (windows nt 6.0; u; en) presto/2.2.15 version/10.00" , "opera opera10 win vista"], // Opera 10
+ ["opera/9.50 (j2me/midp; opera mini/ 4.1.11320/546; u; pt)" , "opera opera9 mobile j2me"], // Opera Mini 10.00 on MAC with OS X
["Opera/10.00 (Macintosh; Intel Mac OS X; u; en) presto/2.2.0" , "opera opera10 mac"], // Opera 10.00 on MAC with OS X
["Opera/9.20 (Macintosh; Intel Mac OS X; U; en)" , "opera opera9 mac"], // Opera 9.20 on MAC with OS X
["Opera/9.02 (Windows NT 5.0; U; en)" , "opera opera9 win"], // Opera 9.02 on Win 2K
@@ -133,14 +134,10 @@
["Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; FDM; Tablet PC 2.0; .NET CLR 4.0.20506; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)" , "ie ie8 win"],
["Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 3.0.04506; Media Center PC 5.0; SLCC1; Tablet PC 2.0)" , "ie ie8 win"],
["Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; InfoPath.2)" , "ie ie8 win"],
-
-
-
-
- ["mozilla/4.0 (compatible; msie 8.0; windows nt 6.0; trident/4.0; slcc1; .net clr 2.0.50727; wwtclient2; infopath.2; officeliveconnector.1.3; officelivepatch.0.0; .net clr 3.0.30618; .net clr 3.5.30729)", "ie ie8 win"],
- ["Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)" , "ie ie8 win"],
- ["Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0" , "ie ie7 win"],
- ["Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; Media Center PC 5.0; .NET CLR 1.1.4322; Windows-Media-Player/10.00.00.3990; InfoPath.2" , "ie ie7 win"], // MSIE 7 running on Windows Vista 64-bit with a ton of 'stuff'
+ ["mozilla/4.0 (compatible; msie 8.0; windows nt 6.0; trident/4.0; slcc1; .net clr 2.0.50727; wwtclient2; infopath.2; officeliveconnector.1.3; officelivepatch.0.0; .net clr 3.0.30618; .net clr 3.5.30729)", "ie ie8 win vista"],
+ ["Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)" , "ie ie8 win vista"],
+ ["Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0" , "ie ie7 win vista"],
+ ["Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; Media Center PC 5.0; .NET CLR 1.1.4322; Windows-Media-Player/10.00.00.3990; InfoPath.2" , "ie ie7 win vista"], // MSIE 7 running on Windows Vista 64-bit with a ton of 'stuff'
["Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; Dealio Deskball 3.0)" , "ie ie7 win"], // MSIE 7 on XP and every version of .NET known to mankind
["Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" , "ie ie6 win"], // Explanation: MSIE 6.x on XP with a skin from neos.tv who seem to specialize in the hospitality (read hotel) industry.
["Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)" , "ie ie5 win"], // MSIE 5.5 on Windows 98
@@ -150,10 +147,11 @@
["Mozilla/2.0 (compatible; MSIE 3.02; Windows CE; 240x320)" , "ie ie3 win"], // MSIE 3.02 on a Pocket PC 2002
["Mozilla/1.22 (compatible; MSIE 2.0; Windows 95)" , "ie ie2 win"], // MSIE 2.0 in windows '95
// Safari
- ["mozilla/5.0 (windows; u; windows nt 6.0; pt-br) applewebkit/528.16 (khtml, like gecko) version/4.0 safari/528.16" , "webkit safari safari4 win"],
+ ["mozilla/5.0 (windows; u; windows nt 6.0; pt-br) applewebkit/528.16 (khtml, like gecko) version/4.0 safari/528.16" , "webkit safari safari4 win vista"],
["Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-gb) AppleWebKit/523.10.6 (KHTML, like Gecko) Version/3.0.4 Safari/523.10.6" , "webkit safari safari3 mac"], // Safari 3.0.4 on Mac OS 10.5.1 Intel
- ["Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3" , "webkit safari safari3 ipod"], // Safari 3.0 for the iPod touch
- ["Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C28 Safari/419.3" , "webkit safari safari3 iphone"], // Safari 3.0 for the iPhone
+ ["Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3" , "webkit safari safari3 mobile ipod"], // Safari 3.0 for the iPod touch
+ ["Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C28 Safari/419.3" , "webkit safari safari3 mobile iphone"], // Safari 3.0 for the iPhone
+ ["Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10", "webkit safari safari4 mobile ipad"], // Safari 4.0 for the iPad
["Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/522.11.1 (KHTML, like Gecko) Version/3.0.3 Safari/522.12.1" , "webkit safari safari3 mac"], // Safari 3.0.3 for Intel version of iMac
["Mozilla/5.0 (Windows; U; Windows NT 5.1; bg) AppleWebKit/522.13.1 (KHTML, like Gecko) Version/3.0.2 Safari/522.13.1" , "webkit safari safari3 win"], // Safari 3.0.2 beta for Windows XP
["Mozilla/5.0 (Windows; U; Windows NT 5.1; ru) AppleWebKit/522.11.3 (KHTML, like Gecko) Version/3.0 Safari/522.11.3" , "webkit safari safari3 win"], // Safari browser V 3.0 Beta for Windows XP SP2
@@ -171,6 +169,8 @@
["Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/51 (like Gecko) Safari/51" , "webkit safari mac"], // Safari browser for MAC OS X
// WebTV
["Mozilla/4.0 WebTV/2.8 (compatible; MSIE 4.0)" , "gecko webtv"], // WebTV 2.8
+ // Blackberry
+ ["blackberry9550/5.0.0.713 profile/midp-2.1 configuration/cldc-1.1 vendorid/105", "mobile blackberry "],
]
document.writeln('<h1>Current Browser</h1>');
@@ -183,7 +183,10 @@
$.each(user_agent_strings,function(index, item) {
ua = item[0];
codes_expected = item[1];
- codes_returned = css_browser_selector(ua).replace(' js','');
+ debug = item[2];
+ codes_returned = css_browser_selector(ua)
+ if(debug) alert("|"+codes_returned+"|")
+ codes_returned = codes_returned.replace(' js','');
if(codes_expected == codes_returned) {
output += '<p style="color: green">'+ua+' - '+codes_returned+'</p>';
passed++;

2 comments on commit 1d3c151

@Tobi319

Honestly this is such a great tool and use it all the time at work. Kudos on the work!

@verbatim
Collaborator
Please sign in to comment.