PageSourceSearch

https://carcassonneapp.com/WebKitDetect.js

js carcassonneapp.com collected 2026-10-02 08:02:17 UTC 5,881 bytes, 179 lines download raw bytes

1/* 
2Copyright (C) 2007 Apple Computer, Inc.  All rights reserved.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions
6are met:
71. Redistributions of source code must retain the above copyright
8   notice, this list of conditions and the following disclaimer.
92. Redistributions in binary form must reproduce the above copyright
10   notice, this list of conditions and the following disclaimer in the
11   documentation and/or other materials provided with the distribution.
12
13THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*/
25
26var WebKitDetect = {  };
27
28// If the user agent is WebKit, returns true. Otherwise, returns false.
29WebKitDetect.isWebKit = function isWebKit()
30{
31    return RegExp(" AppleWebKit/").test(navigator.userAgent);
32}
33
34// If the user agent is WebKit, returns an array of numbers matching the "." separated 
35// fields in the WebKit version number, with an "isNightlyBuild" property specifying
36// whether the user agent is a WebKit nightly build. Otherwise, returns null.
37//
38// Example: 418.10.1 => [ 418, 10, 1 ] isNightlyBuild: false
39WebKitDetect.version = function version() 
40{
41    /* Some example strings: 
42            Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3
43            Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Safari/521.32
44     */
45     
46    // grab (AppleWebKit/)(xxx.x.x)
47    var webKitFields = RegExp("( AppleWebKit/)([^ ]+)").exec(navigator.userAgent);
48    if (!webKitFields || webKitFields.length < 3)
49        return null;
50    var versionString = webKitFields[2];
51
52    var isNightlyBuild = versionString.indexOf("+") != -1;
53
54    // Remove '+' or any other stray characters
55    var invalidCharacter = RegExp("[^\\.0-9]").exec(versionString);
56    if (invalidCharacter)
57        versionString = versionString.slice(0, invalidCharacter.index);
58    
59    var version = versionString.split(".");
60    version.isNightlyBuild = isNightlyBuild;
61    return version;
62}
63
64// If the user agent is a WebKit version greater than or equal to the version specified
65// in the string minimumString, returns true. Returns false otherwise. minimumString 
66// defaults to "".
67//
68// Example usage: WebKitDetect.versionIsAtLeast("418.10.1")
69WebKitDetect.versionIsAtLeast = function versionIsAtLeast(minimumString)
70{
71    function toIntOrZero(s) 
72    {
73        var toInt = parseInt(s);
74        return isNaN(toInt) ? 0 : toInt;
75    }
76
77    if (minimumString === undefined)
78        minimumString = "";
79    
80    var minimum = minimumString.split(".");
81    var version = WebKitDetect.version();
82
83    if (!version)
84        return false;
85        
86    if (version.isNightlyBuild)
87        return true;
88
89    for (var i = 0; i < minimum.length; i++) {
90        var versionField = toIntOrZero(version[i]);
91        var minimumField = toIntOrZero(minimum[i]);
92        
93        if (versionField > minimumField)
94            return true;
95        if (versionField < minimumField)
96            return false;
97    }
98
99    return true;
100}
101
102WebKitDetect.isMobile = function isMobile()
103{
104    return WebKitDetect.isWebKit() && RegExp(" Mobile/").test(navigator.userAgent);
105}
106
107WebKitDetect.mobileDevice = function mobileDevice()
108{
109    if (!WebKitDetect.isMobile())
110        return null;
111        
112    var fields = RegExp("(Mozilla/5.0 \\()([^;]+)").exec(navigator.userAgent);
113    if (!fields || fields.length < 3)
114        return null;
115    return fields[2];
116}
117
118// Example: 1C28 => [ 1, C, 28 ]
119WebKitDetect._mobileVersion = function _mobileVersion(versionString)
120{
121    var fields = RegExp("([0-9]+)([A-Z]+)([0-9]+)").exec(versionString);
122    if (!fields || fields.length != 4)
123        return null;
124    return [ fields[1], fields[2], fields[3] ];
125}
126
127WebKitDetect.mobileVersion = function mobileVersion()
128{
129    // grab (Mobile/)(nxnnn)
130    var fields = RegExp("( Mobile/)([^ ]+)").exec(navigator.userAgent);
131    if (!fields || fields.length < 3)
132        return null;
133    var versionString = fields[2];
134    
135    return WebKitDetect._mobileVersion(versionString);
136}
137
138WebKitDetect.mobileVersionIsAtLeast = function mobileVersionIsAtLeast(minimumString)
139{
140    function toIntOrZero(s) 
141    {
142        var toInt = parseInt(s);
143        return isNaN(toInt) ? 0 : toInt;
144    }
145
146    if (minimumString === undefined)
147        minimumString = "";
148
149    var minimum = WebKitDetect._mobileVersion(minimumString);
150    var version = WebKitDetect.mobileVersion();
151
152    if (!version)
153        return false;
154        
155    var majorVersInt = toIntOrZero(version[0]);
156    var majorMinInt = toIntOrZero(minimum[0]);
157    if (majorVersInt > majorMinInt)
158        return true;
159    if (majorVersInt < majorMinInt)
160        return false;
161    
162    var majorVersAlpha = version[1];
163    var majorMinAlpha = minimum[1];
164    if (majorVersAlpha > majorMinAlpha)
165        return true;
166    if (majorVersAlpha < majorMinAlpha)
167        return false;
168    
169    var minorVersInt = toIntOrZero(version[2]);
170    var minorMinInt = toIntOrZero(minimum[2]);
171    if (minorVersInt > minorMinInt)
172        return true;
173    if (minorVersInt < minorMinInt)
174        return false;
175    
176    return true;
177}
178
179

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.