Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: static/js/vendor/bowser.js

Issue 29766571: Fixes #55 - Updated install button on Samsung Browser for Android (Closed) Base URL: https://hg.adblockplus.org/web.adblockplus.org
Patch Set: First draft Created April 30, 2018, 9:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pages/android.tmpl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*!
2 * Bowser - a browser detector
3 * https://github.com/ded/bowser
4 * MIT License | (c) Dustin Diaz 2015
5 */
6
7 !function (root, name, definition) {
8 if (typeof module != 'undefined' && module.exports) module.exports = definitio n()
9 else if (typeof define == 'function' && define.amd) define(name, definition)
10 else root[name] = definition()
11 }(this, 'bowser', function () {
12 /**
13 * See useragents.js for examples of navigator.userAgent
14 */
15
16 var t = true
17
18 function detect(ua) {
19
20 function getFirstMatch(regex) {
21 var match = ua.match(regex);
22 return (match && match.length > 1 && match[1]) || '';
23 }
24
25 function getSecondMatch(regex) {
26 var match = ua.match(regex);
27 return (match && match.length > 1 && match[2]) || '';
28 }
29
30 var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase()
31 , likeAndroid = /like android/i.test(ua)
32 , android = !likeAndroid && /android/i.test(ua)
33 , nexusMobile = /nexus\s*[0-6]\s*/i.test(ua)
34 , nexusTablet = !nexusMobile && /nexus\s*[0-9]+/i.test(ua)
35 , chromeos = /CrOS/.test(ua)
36 , silk = /silk/i.test(ua)
37 , sailfish = /sailfish/i.test(ua)
38 , tizen = /tizen/i.test(ua)
39 , webos = /(web|hpw)os/i.test(ua)
40 , windowsphone = /windows phone/i.test(ua)
41 , samsungBrowser = /SamsungBrowser/i.test(ua)
42 , windows = !windowsphone && /windows/i.test(ua)
43 , mac = !iosdevice && !silk && /macintosh/i.test(ua)
44 , linux = !android && !sailfish && !tizen && !webos && /linux/i.test(ua)
45 , edgeVersion = getSecondMatch(/edg([ea]|ios)\/(\d+(\.\d+)?)/i)
46 , versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i)
47 , tablet = /tablet/i.test(ua) && !/tablet pc/i.test(ua)
48 , mobile = !tablet && /[^-]mobi/i.test(ua)
49 , xbox = /xbox/i.test(ua)
50 , result
51
52 if (/opera/i.test(ua)) {
53 // an old Opera
54 result = {
55 name: 'Opera'
56 , opera: t
57 , version: versionIdentifier || getFirstMatch(/(?:opera|opr|opios)[\s\/](\ d+(\.\d+)?)/i)
58 }
59 } else if (/opr\/|opios/i.test(ua)) {
60 // a new Opera
61 result = {
62 name: 'Opera'
63 , opera: t
64 , version: getFirstMatch(/(?:opr|opios)[\s\/](\d+(\.\d+)?)/i) || version Identifier
65 }
66 }
67 else if (/SamsungBrowser/i.test(ua)) {
68 result = {
69 name: 'Samsung Internet for Android'
70 , samsungBrowser: t
71 , version: versionIdentifier || getFirstMatch(/(?:SamsungBrowser)[\s\/]( \d+(\.\d+)?)/i)
72 }
73 }
74 else if (/coast/i.test(ua)) {
75 result = {
76 name: 'Opera Coast'
77 , coast: t
78 , version: versionIdentifier || getFirstMatch(/(?:coast)[\s\/](\d+(\.\d+ )?)/i)
79 }
80 }
81 else if (/yabrowser/i.test(ua)) {
82 result = {
83 name: 'Yandex Browser'
84 , yandexbrowser: t
85 , version: versionIdentifier || getFirstMatch(/(?:yabrowser)[\s\/](\d+(\.\ d+)?)/i)
86 }
87 }
88 else if (/ucbrowser/i.test(ua)) {
89 result = {
90 name: 'UC Browser'
91 , ucbrowser: t
92 , version: getFirstMatch(/(?:ucbrowser)[\s\/](\d+(?:\.\d+)+)/i)
93 }
94 }
95 else if (/mxios/i.test(ua)) {
96 result = {
97 name: 'Maxthon'
98 , maxthon: t
99 , version: getFirstMatch(/(?:mxios)[\s\/](\d+(?:\.\d+)+)/i)
100 }
101 }
102 else if (/epiphany/i.test(ua)) {
103 result = {
104 name: 'Epiphany'
105 , epiphany: t
106 , version: getFirstMatch(/(?:epiphany)[\s\/](\d+(?:\.\d+)+)/i)
107 }
108 }
109 else if (/puffin/i.test(ua)) {
110 result = {
111 name: 'Puffin'
112 , puffin: t
113 , version: getFirstMatch(/(?:puffin)[\s\/](\d+(?:\.\d+)?)/i)
114 }
115 }
116 else if (/sleipnir/i.test(ua)) {
117 result = {
118 name: 'Sleipnir'
119 , sleipnir: t
120 , version: getFirstMatch(/(?:sleipnir)[\s\/](\d+(?:\.\d+)+)/i)
121 }
122 }
123 else if (/k-meleon/i.test(ua)) {
124 result = {
125 name: 'K-Meleon'
126 , kMeleon: t
127 , version: getFirstMatch(/(?:k-meleon)[\s\/](\d+(?:\.\d+)+)/i)
128 }
129 }
130 else if (windowsphone) {
131 result = {
132 name: 'Windows Phone'
133 , osname: 'Windows Phone'
134 , windowsphone: t
135 }
136 if (edgeVersion) {
137 result.msedge = t
138 result.version = edgeVersion
139 }
140 else {
141 result.msie = t
142 result.version = getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i)
143 }
144 }
145 else if (/msie|trident/i.test(ua)) {
146 result = {
147 name: 'Internet Explorer'
148 , msie: t
149 , version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i)
150 }
151 } else if (chromeos) {
152 result = {
153 name: 'Chrome'
154 , osname: 'Chrome OS'
155 , chromeos: t
156 , chromeBook: t
157 , chrome: t
158 , version: getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
159 }
160 } else if (/edg([ea]|ios)/i.test(ua)) {
161 result = {
162 name: 'Microsoft Edge'
163 , msedge: t
164 , version: edgeVersion
165 }
166 }
167 else if (/vivaldi/i.test(ua)) {
168 result = {
169 name: 'Vivaldi'
170 , vivaldi: t
171 , version: getFirstMatch(/vivaldi\/(\d+(\.\d+)?)/i) || versionIdentifier
172 }
173 }
174 else if (sailfish) {
175 result = {
176 name: 'Sailfish'
177 , osname: 'Sailfish OS'
178 , sailfish: t
179 , version: getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i)
180 }
181 }
182 else if (/seamonkey\//i.test(ua)) {
183 result = {
184 name: 'SeaMonkey'
185 , seamonkey: t
186 , version: getFirstMatch(/seamonkey\/(\d+(\.\d+)?)/i)
187 }
188 }
189 else if (/firefox|iceweasel|fxios/i.test(ua)) {
190 result = {
191 name: 'Firefox'
192 , firefox: t
193 , version: getFirstMatch(/(?:firefox|iceweasel|fxios)[ \/](\d+(\.\d+)?)/i)
194 }
195 if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
196 result.firefoxos = t
197 result.osname = 'Firefox OS'
198 }
199 }
200 else if (silk) {
201 result = {
202 name: 'Amazon Silk'
203 , silk: t
204 , version : getFirstMatch(/silk\/(\d+(\.\d+)?)/i)
205 }
206 }
207 else if (/phantom/i.test(ua)) {
208 result = {
209 name: 'PhantomJS'
210 , phantom: t
211 , version: getFirstMatch(/phantomjs\/(\d+(\.\d+)?)/i)
212 }
213 }
214 else if (/slimerjs/i.test(ua)) {
215 result = {
216 name: 'SlimerJS'
217 , slimer: t
218 , version: getFirstMatch(/slimerjs\/(\d+(\.\d+)?)/i)
219 }
220 }
221 else if (/blackberry|\bbb\d+/i.test(ua) || /rim\stablet/i.test(ua)) {
222 result = {
223 name: 'BlackBerry'
224 , osname: 'BlackBerry OS'
225 , blackberry: t
226 , version: versionIdentifier || getFirstMatch(/blackberry[\d]+\/(\d+(\.\d+ )?)/i)
227 }
228 }
229 else if (webos) {
230 result = {
231 name: 'WebOS'
232 , osname: 'WebOS'
233 , webos: t
234 , version: versionIdentifier || getFirstMatch(/w(?:eb)?osbrowser\/(\d+(\.\ d+)?)/i)
235 };
236 /touchpad\//i.test(ua) && (result.touchpad = t)
237 }
238 else if (/bada/i.test(ua)) {
239 result = {
240 name: 'Bada'
241 , osname: 'Bada'
242 , bada: t
243 , version: getFirstMatch(/dolfin\/(\d+(\.\d+)?)/i)
244 };
245 }
246 else if (tizen) {
247 result = {
248 name: 'Tizen'
249 , osname: 'Tizen'
250 , tizen: t
251 , version: getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i) || versio nIdentifier
252 };
253 }
254 else if (/qupzilla/i.test(ua)) {
255 result = {
256 name: 'QupZilla'
257 , qupzilla: t
258 , version: getFirstMatch(/(?:qupzilla)[\s\/](\d+(?:\.\d+)+)/i) || versio nIdentifier
259 }
260 }
261 else if (/chromium/i.test(ua)) {
262 result = {
263 name: 'Chromium'
264 , chromium: t
265 , version: getFirstMatch(/(?:chromium)[\s\/](\d+(?:\.\d+)?)/i) || versio nIdentifier
266 }
267 }
268 else if (/chrome|crios|crmo/i.test(ua)) {
269 result = {
270 name: 'Chrome'
271 , chrome: t
272 , version: getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
273 }
274 }
275 else if (android) {
276 result = {
277 name: 'Android'
278 , version: versionIdentifier
279 }
280 }
281 else if (/safari|applewebkit/i.test(ua)) {
282 result = {
283 name: 'Safari'
284 , safari: t
285 }
286 if (versionIdentifier) {
287 result.version = versionIdentifier
288 }
289 }
290 else if (iosdevice) {
291 result = {
292 name : iosdevice == 'iphone' ? 'iPhone' : iosdevice == 'ipad' ? 'iPad' : 'iPod'
293 }
294 // WTF: version is not part of user agent in web apps
295 if (versionIdentifier) {
296 result.version = versionIdentifier
297 }
298 }
299 else if(/googlebot/i.test(ua)) {
300 result = {
301 name: 'Googlebot'
302 , googlebot: t
303 , version: getFirstMatch(/googlebot\/(\d+(\.\d+))/i) || versionIdentifier
304 }
305 }
306 else {
307 result = {
308 name: getFirstMatch(/^(.*)\/(.*) /),
309 version: getSecondMatch(/^(.*)\/(.*) /)
310 };
311 }
312
313 // set webkit or gecko flag for browsers based on these engines
314 if (!result.msedge && /(apple)?webkit/i.test(ua)) {
315 if (/(apple)?webkit\/537\.36/i.test(ua)) {
316 result.name = result.name || "Blink"
317 result.blink = t
318 } else {
319 result.name = result.name || "Webkit"
320 result.webkit = t
321 }
322 if (!result.version && versionIdentifier) {
323 result.version = versionIdentifier
324 }
325 } else if (!result.opera && /gecko\//i.test(ua)) {
326 result.name = result.name || "Gecko"
327 result.gecko = t
328 result.version = result.version || getFirstMatch(/gecko\/(\d+(\.\d+)?)/i)
329 }
330
331 // set OS flags for platforms that have multiple browsers
332 if (!result.windowsphone && (android || result.silk)) {
333 result.android = t
334 result.osname = 'Android'
335 } else if (!result.windowsphone && iosdevice) {
336 result[iosdevice] = t
337 result.ios = t
338 result.osname = 'iOS'
339 } else if (mac) {
340 result.mac = t
341 result.osname = 'macOS'
342 } else if (xbox) {
343 result.xbox = t
344 result.osname = 'Xbox'
345 } else if (windows) {
346 result.windows = t
347 result.osname = 'Windows'
348 } else if (linux) {
349 result.linux = t
350 result.osname = 'Linux'
351 }
352
353 function getWindowsVersion (s) {
354 switch (s) {
355 case 'NT': return 'NT'
356 case 'XP': return 'XP'
357 case 'NT 5.0': return '2000'
358 case 'NT 5.1': return 'XP'
359 case 'NT 5.2': return '2003'
360 case 'NT 6.0': return 'Vista'
361 case 'NT 6.1': return '7'
362 case 'NT 6.2': return '8'
363 case 'NT 6.3': return '8.1'
364 case 'NT 10.0': return '10'
365 default: return undefined
366 }
367 }
368
369 // OS version extraction
370 var osVersion = '';
371 if (result.windows) {
372 osVersion = getWindowsVersion(getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?) /i))
373 } else if (result.windowsphone) {
374 osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
375 } else if (result.mac) {
376 osVersion = getFirstMatch(/Mac OS X (\d+([_\.\s]\d+)*)/i);
377 osVersion = osVersion.replace(/[_\s]/g, '.');
378 } else if (iosdevice) {
379 osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i);
380 osVersion = osVersion.replace(/[_\s]/g, '.');
381 } else if (android) {
382 osVersion = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i);
383 } else if (result.webos) {
384 osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i);
385 } else if (result.blackberry) {
386 osVersion = getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i);
387 } else if (result.bada) {
388 osVersion = getFirstMatch(/bada\/(\d+(\.\d+)*)/i);
389 } else if (result.tizen) {
390 osVersion = getFirstMatch(/tizen[\/\s](\d+(\.\d+)*)/i);
391 }
392 if (osVersion) {
393 result.osversion = osVersion;
394 }
395
396 // device type extraction
397 var osMajorVersion = !result.windows && osVersion.split('.')[0];
398 if (
399 tablet
400 || nexusTablet
401 || iosdevice == 'ipad'
402 || (android && (osMajorVersion == 3 || (osMajorVersion >= 4 && !mobile)))
403 || result.silk
404 ) {
405 result.tablet = t
406 } else if (
407 mobile
408 || iosdevice == 'iphone'
409 || iosdevice == 'ipod'
410 || android
411 || nexusMobile
412 || result.blackberry
413 || result.webos
414 || result.bada
415 ) {
416 result.mobile = t
417 }
418
419 // Graded Browser Support
420 // http://developer.yahoo.com/yui/articles/gbs
421 if (result.msedge ||
422 (result.msie && result.version >= 10) ||
423 (result.yandexbrowser && result.version >= 15) ||
424 (result.vivaldi && result.version >= 1.0) ||
425 (result.chrome && result.version >= 20) ||
426 (result.samsungBrowser && result.version >= 4) ||
427 (result.firefox && result.version >= 20.0) ||
428 (result.safari && result.version >= 6) ||
429 (result.opera && result.version >= 10.0) ||
430 (result.ios && result.osversion && result.osversion.split(".")[0] >= 6) ||
431 (result.blackberry && result.version >= 10.1)
432 || (result.chromium && result.version >= 20)
433 ) {
434 result.a = t;
435 }
436 else if ((result.msie && result.version < 10) ||
437 (result.chrome && result.version < 20) ||
438 (result.firefox && result.version < 20.0) ||
439 (result.safari && result.version < 6) ||
440 (result.opera && result.version < 10.0) ||
441 (result.ios && result.osversion && result.osversion.split(".")[0] < 6)
442 || (result.chromium && result.version < 20)
443 ) {
444 result.c = t
445 } else result.x = t
446
447 return result
448 }
449
450 var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent || '' : '')
451
452 bowser.test = function (browserList) {
453 for (var i = 0; i < browserList.length; ++i) {
454 var browserItem = browserList[i];
455 if (typeof browserItem=== 'string') {
456 if (browserItem in bowser) {
457 return true;
458 }
459 }
460 }
461 return false;
462 }
463
464 /**
465 * Get version precisions count
466 *
467 * @example
468 * getVersionPrecision("1.10.3") // 3
469 *
470 * @param {string} version
471 * @return {number}
472 */
473 function getVersionPrecision(version) {
474 return version.split(".").length;
475 }
476
477 /**
478 * Array::map polyfill
479 *
480 * @param {Array} arr
481 * @param {Function} iterator
482 * @return {Array}
483 */
484 function map(arr, iterator) {
485 var result = [], i;
486 if (Array.prototype.map) {
487 return Array.prototype.map.call(arr, iterator);
488 }
489 for (i = 0; i < arr.length; i++) {
490 result.push(iterator(arr[i]));
491 }
492 return result;
493 }
494
495 /**
496 * Calculate browser version weight
497 *
498 * @example
499 * compareVersions(['1.10.2.1', '1.8.2.1.90']) // 1
500 * compareVersions(['1.010.2.1', '1.09.2.1.90']); // 1
501 * compareVersions(['1.10.2.1', '1.10.2.1']); // 0
502 * compareVersions(['1.10.2.1', '1.0800.2']); // -1
503 *
504 * @param {Array<String>} versions versions to compare
505 * @return {Number} comparison result
506 */
507 function compareVersions(versions) {
508 // 1) get common precision for both versions, for example for "10.0" and "9" it should be 2
509 var precision = Math.max(getVersionPrecision(versions[0]), getVersionPrecisi on(versions[1]));
510 var chunks = map(versions, function (version) {
511 var delta = precision - getVersionPrecision(version);
512
513 // 2) "9" -> "9.0" (for precision = 2)
514 version = version + new Array(delta + 1).join(".0");
515
516 // 3) "9.0" -> ["000000000"", "000000009"]
517 return map(version.split("."), function (chunk) {
518 return new Array(20 - chunk.length).join("0") + chunk;
519 }).reverse();
520 });
521
522 // iterate in reverse order by reversed chunks array
523 while (--precision >= 0) {
524 // 4) compare: "000000009" > "000000010" = false (but "9" > "10" = true)
525 if (chunks[0][precision] > chunks[1][precision]) {
526 return 1;
527 }
528 else if (chunks[0][precision] === chunks[1][precision]) {
529 if (precision === 0) {
530 // all version chunks are same
531 return 0;
532 }
533 }
534 else {
535 return -1;
536 }
537 }
538 }
539
540 /**
541 * Check if browser is unsupported
542 *
543 * @example
544 * bowser.isUnsupportedBrowser({
545 * msie: "10",
546 * firefox: "23",
547 * chrome: "29",
548 * safari: "5.1",
549 * opera: "16",
550 * phantom: "534"
551 * });
552 *
553 * @param {Object} minVersions map of minimal version to browser
554 * @param {Boolean} [strictMode = false] flag to return false if browser wasn 't found in map
555 * @param {String} [ua] user agent string
556 * @return {Boolean}
557 */
558 function isUnsupportedBrowser(minVersions, strictMode, ua) {
559 var _bowser = bowser;
560
561 // make strictMode param optional with ua param usage
562 if (typeof strictMode === 'string') {
563 ua = strictMode;
564 strictMode = void(0);
565 }
566
567 if (strictMode === void(0)) {
568 strictMode = false;
569 }
570 if (ua) {
571 _bowser = detect(ua);
572 }
573
574 var version = "" + _bowser.version;
575 for (var browser in minVersions) {
576 if (minVersions.hasOwnProperty(browser)) {
577 if (_bowser[browser]) {
578 if (typeof minVersions[browser] !== 'string') {
579 throw new Error('Browser version in the minVersion map should be a s tring: ' + browser + ': ' + String(minVersions));
580 }
581
582 // browser version and min supported version.
583 return compareVersions([version, minVersions[browser]]) < 0;
584 }
585 }
586 }
587
588 return strictMode; // not found
589 }
590
591 /**
592 * Check if browser is supported
593 *
594 * @param {Object} minVersions map of minimal version to browser
595 * @param {Boolean} [strictMode = false] flag to return false if browser wasn 't found in map
596 * @param {String} [ua] user agent string
597 * @return {Boolean}
598 */
599 function check(minVersions, strictMode, ua) {
600 return !isUnsupportedBrowser(minVersions, strictMode, ua);
601 }
602
603 bowser.isUnsupportedBrowser = isUnsupportedBrowser;
604 bowser.compareVersions = compareVersions;
605 bowser.check = check;
606
607 /*
608 * Set our detect method to the main bowser object so we can
609 * reuse it to test other user agents.
610 * This is needed to implement future tests.
611 */
612 bowser._detect = detect;
613
614 /*
615 * Set our detect public method to the main bowser object
616 * This is needed to implement bowser in server side
617 */
618 bowser.detect = detect;
619 return bowser
620 });
OLDNEW
« no previous file with comments | « pages/android.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld