1/* initGeetest 1.0.0 2 * ç¨äºå è½½id对åºçéªè¯ç åºï¼å¹¶æ¯æå®æºæ¨¡å¼ 3 * æ´é² initGeetest è¿è¡éªè¯ç çåå§å 4 * ä¸è¬ä¸éè¦ç¨æ·è¿è¡ä¿®æ¹ 5 */ 6(function (global, factory) { 7 'use strict' 8 if (typeof module === 'object' && typeof module.exports === 'object') { 9 // CommonJS 10 module.exports = global.document 11 ? factory(global, true) 12 : function (w) { 13 if (!w.document) { 14 throw new Error('Geetest requires a window with a document') 15 } 16 return factory(w) 17 } 18 } else { 19 factory(global) 20 } 21})(typeof window !== 'undefined' ? window : this, function (window, noGlobal) { 22 'use strict' 23 if (typeof window === 'undefined') { 24 throw new Error('Geetest requires browser environment') 25 } 26 var document = window.document 27 var Math = window.Math 28 var head = document.getElementsByTagName('head')[0] 29 30 function _Object (obj) { 31 this._obj = obj 32 } 33 34 _Object.prototype = { 35 _each: function (process) { 36 var _obj = this._obj 37 for (var k in _obj) { 38 if (_obj.hasOwnProperty(k)) { 39 process(k, _obj[k]) 40 } 41 } 42 return this 43 } 44 } 45 function Config (config) { 46 var self = this 47 new _Object(config)._each(function (key, value) { 48 self[key] = value 49 }) 50 } 51 52 Config.prototype = { 53 api_server: 'api.geetest.com', 54 protocol: 'http://', 55 type_path: '/gettype.php', 56 fallback_config: { 57 slide: { 58 static_servers: ['static.geetest.com', 'dn-staticdown.qbox.me'], 59 type: 'slide', 60 slide: '/static/js/geetest.0.0.0.js' 61 }, 62 fullpage: { 63 static_servers: ['static.geetest.com', 'dn-staticdown.qbox.me'], 64 type: 'fullpage', 65 fullpage: '/static/static/js/common/fullpage.0.0.0.js' 66 } 67 }, 68 _get_fallback_config: function () { 69 var self = this 70 if (isString(self.type)) { 71 return self.fallback_config[self.type] 72 } else if (self.new_captcha) { 73 return self.fallback_config.fullpage 74 } else { 75 return self.fallback_config.slide 76 } 77 }, 78 _extend: function (obj) { 79 var self = this 80 new _Object(obj)._each(function (key, value) { 81 self[key] = value 82 }) 83 } 84 } 85 var isNumber = function (value) { 86 return (typeof value === 'number') 87 } 88 var isString = function (value) { 89 return (typeof value === 'string') 90 } 91 var isBoolean = function (value) { 92 return (typeof value === 'boolean') 93 } 94 var isObject = function (value) { 95 return (typeof value === 'object' && value !== null) 96 } 97 var isFunction = function (value) { 98 return (typeof value === 'function') 99 } 100 var callbacks = {} 101 var status = {} 102 var random = function () { 103 return parseInt(Math.random() * 10000) + (new Date()).valueOf() 104 } 105 var loadScript = function (url, cb) { 106 var script = document.createElement('script') 107 script.charset = 'UTF-8' 108 script.async = true 109 script.onerror = function () { 110 cb(true) 111 } 112 var loaded = false 113 script.onload = script.onreadystatechange = function () { 114 if (!loaded && 115 (!script.readyState || 116 script.readyState === 'loaded' || 117 script.readyState === 'complete')) { 118 loaded = true 119 setTimeout(function () { 120 cb(false) 121 }, 0) 122 } 123 } 124 script.src = url 125 head.appendChild(script) 126 } 127 var normalizeDomain = function (domain) { 128 return domain.replace(/^https?:\/\/|\/$/g, '') 129 } 130 var normalizePath = function (path) { 131 path = path.replace(/\/+/g, '/') 132 if (path.indexOf('/') !== 0) { 133 path = '/' + path 134 } 135 return path 136 } 137 var normalizeQuery = function (query) { 138 if (!query) { 139 return '' 140 } 141 var q = '?' 142 new _Object(query)._each(function (key, value) { 143 if (isString(value) || isNumber(value) || isBoolean(value)) { 144 q = q + encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&' 145 } 146 }) 147 if (q === '?') { 148 q = '' 149 } 150 return q.replace(/&$/, '') 151 } 152 var makeURL = function (protocol, domain, path, query) { 153 domain = normalizeDomain(domain) 154 155 var url = normalizePath(path) + normalizeQuery(query) 156 if (domain) { 157 url = protocol + domain + url 158 } 159 160 return url 161 } 162 var load = function (protocol, domains, path, query, cb) { 163 var tryRequest = function (at) { 164 var url = makeURL(protocol, domains[at], path, query) 165 loadScript(url, function (err) { 166 if (err) { 167 if (at >= domains.length - 1) { 168 cb(true) 169 } else { 170 tryRequest(at + 1) 171 } 172 } else { 173 cb(false) 174 } 175 }) 176 } 177 tryRequest(0) 178 } 179 var jsonp = function (domains, path, config, callback) { 180 if (isObject(config.getLib)) { 181 config._extend(config.getLib) 182 callback(config) 183 return 184 } 185 if (config.offline) { 186 callback(config._get_fallback_config()) 187 return 188 } 189 var cb = 'geetest_' + random() 190 window[cb] = function (data) { 191 if (data.status === 'success') { 192 callback(data.data) 193 } else if (!data.status) { 194 callback(data) 195 } else { 196 callback(config._get_fallback_config()) 197 } 198 window[cb] = undefined
199 try { 200 delete window[cb] 201 } catch (e) { 202 } 203 } 204 load(config.protocol, domains, path, { 205 gt: config.gt, 206 callback: cb 207 }, function (err) { 208 if (err) { 209 callback(config._get_fallback_config()) 210 } 211 }) 212 } 213 var throwError = function (errorType, config) { 214 var errors = { 215 networkError: 'ç½ç»é误' 216 } 217 if (typeof config.onError === 'function') { 218 config.onError(errors[errorType]) 219 } else { 220 throw new Error(errors[errorType]) 221 } 222 } 223 var detect = function () { 224 return !!window.Geetest 225 } 226 if (detect()) { 227 status.slide = 'loaded' 228 } 229 var initGeetest = function (userConfig, callback) { 230 var config = new Config(userConfig) 231 if (userConfig.https) { 232 config.protocol = 'https://' 233 } else if (!userConfig.protocol) { 234 config.protocol = window.location.protocol + '//' 235 } 236 jsonp([config.api_server || config.apiserver], config.type_path, config, function (newConfig) { 237 var type = newConfig.type 238 var init = function () { 239 config._extend(newConfig) 240 callback(new window.Geetest(config)) 241 } 242 callbacks[type] = callbacks[type] || [] 243 var s = status[type] || 'init' 244 if (s === 'init') { 245 status[type] = 'loading' 246 callbacks[type].push(init) 247 load(config.protocol, newConfig.static_servers || newConfig.domains, newConfig[type] || newConfig.path, null, function (err) { 248 if (err) { 249 status[type] = 'fail' 250 throwError('networkError', config) 251 } else { 252 status[type] = 'loaded' 253 var cbs = callbacks[type] 254 for (var i = 0, len = cbs.length; i < len; i = i + 1) { 255 var cb = cbs[i] 256 if (isFunction(cb)) { 257 cb() 258 } 259 } 260 callbacks[type] = [] 261 } 262 }) 263 } else if (s === 'loaded') { 264 init() 265 } else if (s === 'fail') { 266 throwError('networkError', config) 267 } else if (s === 'loading') { 268 callbacks[type].push(init) 269 } 270 }) 271 } 272 window.initGeetest = initGeetest 273 return initGeetest 274})
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.