1"v1.0.4 Botion Inc."; 2 3(function (window) { 4 "use strict"; 5 if (typeof window === 'undefined') { 6 throw new Error('Botion requires browser environment'); 7 } 8 9var document = window.document; 10var Math = window.Math; 11var head = document.getElementsByTagName("head")[0]; 12var TIMEOUT = 3000; 13 14function _Object(obj) { 15 this._obj = obj; 16} 17 18_Object.prototype = { 19 _each: function (process) { 20 var _obj = this._obj; 21 for (var k in _obj) { 22 if (_obj.hasOwnProperty(k)) { 23 process(k, _obj[k]); 24 } 25 } 26 return this; 27 }, 28 _extend: function (obj){ 29 var self = this; 30 new _Object(obj)._each(function (key, value){ 31 self._obj[key] = value; 32 }) 33 } 34}; 35 36var uuid = function () { 37 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { 38 var r = Math.random() * 16 | 0; 39 var v = c === 'x' ? r : (r & 0x3 | 0x8); 40 return v.toString(16); 41 }); 42 }; 43 44function Config(config) { 45 var self = this; 46 new _Object(config)._each(function (key, value) { 47 self[key] = value; 48 }); 49} 50 51Config.prototype = { 52 apiServers: ['bcaptcha.botion.com','bcaptcha.netshunt.com','bcaptcha.botlabpro.com'], 53 staticServers: ["static.botion.com",'static.netshunt.com','static.botlabpro.com'], 54 protocol: 'http://', 55 typePath: '/load', 56 fallback_config: { 57 bypass: { 58 staticServers: ["static.botion.com",'static.netshunt.com'], 59 type: 'bypass', 60 bypass: '/v1/bypass.js' 61 } 62 }, 63 _get_fallback_config: function () { 64 var self = this; 65 if (isString(self.type)) { 66 return self.fallback_config[self.type]; 67 } else { 68 return self.fallback_config.bypass; 69 } 70 }, 71 _extend: function (obj) { 72 var self = this; 73 new _Object(obj)._each(function (key, value) { 74 self[key] = value; 75 }) 76 } 77}; 78var isNumber = function (value) { 79 return (typeof value === 'number'); 80}; 81var isString = function (value) { 82 return (typeof value === 'string'); 83}; 84var isBoolean = function (value) { 85 return (typeof value === 'boolean'); 86}; 87var isObject = function (value) { 88 return (typeof value === 'object' && value !== null); 89}; 90var isFunction = function (value) { 91 return (typeof value === 'function'); 92}; 93var MOBILE = /Mobi/i.test(navigator.userAgent); 94 95var callbacks = {}; 96var status = {}; 97 98var random = function () { 99 return parseInt(Math.random() * 10000) + (new Date()).valueOf(); 100}; 101 102 103var bind = function(target,context){ 104 if(typeof target !== 'function'){ 105 return; 106 } 107 var args = Array.prototype.slice.call(arguments,2); 108 109 if(Function.prototype.bind){ 110 return target.bind(context, args); 111 }else { 112 return function(){ 113 var _args = Array.prototype.slice.call(arguments); 114 return target.apply(context,args.concat(_args)); 115 } 116 } 117} 118 119 120 121var toString = Object.prototype.toString; 122 123var _isFunction = function(obj) { 124 return typeof(obj) === 'function'; 125}; 126var _isObject = function(obj) { 127 return obj === Object(obj); 128}; 129var _isArray = function(obj) { 130 return toString.call(obj) == '[object Array]'; 131}; 132var _isDate = function(obj) { 133 return toString.call(obj) == '[object Date]'; 134}; 135var _isRegExp = function(obj) { 136 return toString.call(obj) == '[object RegExp]'; 137}; 138var _isBoolean = function(obj) { 139 return toString.call(obj) == '[object Boolean]'; 140}; 141 142 143function resolveKey(input){ 144 return input.replace(/(\S)(_([a-zA-Z]))/g, function(match, $1, $2, $3){ 145 return $1 + $3.toUpperCase() || ""; 146 }) 147} 148 149function camelizeKeys(input, convert){ 150 if(!_isObject(input) || _isDate(input) || _isRegExp(input) || _isBoolean(input) || _isFunction(input)){ 151 return convert ? resolveKey(input) : input; 152 } 153 154 if(_isArray(input)){ 155 var temp = []; 156 for(var i = 0; i < input.length; i++){ 157 temp.push(camelizeKeys(input[i])); 158 } 159 160 }else { 161 var temp = {}; 162 for(var prop in input){ 163 if(input.hasOwnProperty(prop)){ 164 temp[camelizeKeys(prop, true)] = camelizeKeys(input[prop]); 165 } 166 } 167 } 168 return temp; 169} 170 171var loadScript = function (url, cb, timeout) { 172 var script = document.createElement("script"); 173 script.charset = "UTF-8"; 174 script.async = true; 175 176 if ( /static\.botion\.com/g.test(url)) { 177 script.crossOrigin = "anonymous"; 178 } 179 180 script.onerror = function () { 181 cb(true); 182 loaded = true; 183 }; 184 var loaded = false;
185 script.onload = script.onreadystatechange = function () { 186 if (!loaded && 187 (!script.readyState || 188 "loaded" === script.readyState || 189 "complete" === script.readyState)) { 190 191 loaded = true; 192 setTimeout(function () { 193 cb(false); 194 }, 0); 195 } 196 }; 197 script.src = url; 198 head.appendChild(script); 199 200 setTimeout(function () { 201 if (!loaded) { 202 script.onerror = script.onload = null; 203 script.remove && script.remove(); 204 cb(true); 205 } 206 }, timeout || TIMEOUT); 207}; 208 209var normalizeDomain = function (domain) { 210 return domain.replace(/^https?:\/\/|\/$/g, ''); 211}; 212var normalizePath = function (path) { 213 path = path.replace(/\/+/g, '/'); 214 if (path.indexOf('/') !== 0) { 215 path = '/' + path; 216 } 217 return path; 218}; 219var normalizeQuery = function (query) { 220 if (!query) { 221 return ''; 222 } 223 var q = '?'; 224 new _Object(query)._each(function (key, value) { 225 if (isString(value) || isNumber(value) || isBoolean(value)) { 226 q = q + encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&'; 227 } 228 }); 229 if (q === '?') { 230 q = ''; 231 } 232 return q.replace(/&$/, ''); 233}; 234var makeURL = function (protocol, domain, path, query) { 235 domain = normalizeDomain(domain); 236 237 var url = normalizePath(path) + normalizeQuery(query); 238 if (domain) { 239 url = protocol + domain + url; 240 } 241 242 return url; 243}; 244 245var load = function (config, protocol, domains, path, query, cb, handleCb) { 246 var tryRequest = function (at) { 247 248 if(handleCb){ 249 var cbName = "botion_" + random(); 250 window[cbName] = bind(handleCb, null, cbName); 251 query.callback = cbName; 252 } 253 var url = makeURL(protocol, domains[at], path, query); 254 loadScript(url, function (err) { 255 if (err) { 256 if(cbName){ 257 try { 258 window[cbName] = function(){ 259 window[cbName] = null; 260 } 261 } catch (e) {} 262 } 263 264 if (at >= domains.length - 1) { 265 cb(true); 266 // report gettype error 267 } else { 268 tryRequest(at + 1); 269 } 270 } else { 271 cb(false); 272 } 273 }, config.timeout); 274 }; 275 tryRequest(0); 276}; 277 278 279var jsonp = function (domains, path, config, callback) { 280 281 var handleCb = function (cbName, data) { 282 283 284 if (data.status == 'success') { 285 callback(data.data); 286 } else if (!data.status) { 287 callback(data); 288 } else { 289 callback(data); 290 } 291 window[cbName] = undefined; 292 try { 293 delete window[cbName]; 294 } catch (e) { 295 } 296 }; 297 298 load(config, config.protocol, domains, path, { 299 captcha_id: config.captchaId, 300 challenge: config.challenge || uuid(), 301 client_type: MOBILE? 'h5':'web', 302 risk_type: config.riskType, 303 call_type: config.callType, 304 lang: config.language? config.language : navigator.appName === 'Netscape' ? navigator.language.toLowerCase() : navigator.userLanguage.toLowerCase() 305 }, function (err) { 306 if(err && typeof config.offlineCb === 'function'){ 307 config.offlineCb(); 308 return; 309 } 310 311 if(err){ 312 callback(config._get_fallback_config()); 313 } 314 }, handleCb); 315}; 316 317var throwError = function (errorType, config, errObj) { 318 var errors = { 319 networkError: 'Network error' 320 }; 321 if (typeof config.onError === 'function') { 322 config.onError({ 323 desc: errObj.desc, 324 msg: errObj.msg, 325 code: errObj.code 326 }); 327 } else { 328 throw new Error(errors[errorType]); 329 } 330}; 331 332var detect = function () { 333 return window.Botion || document.getElementById("ns_lib"); 334}; 335 336if (detect()) { 337 status.slide = "loaded"; 338} 339var BotionIsLoad = function (fname) { 340 var BotionIsLoad = false;
341 var tags = { js: 'script', css: 'link' }; 342 var tagname = tags[fname.split('.').pop()]; 343 if (tagname !== undefined) { 344 var elts = document.getElementsByTagName(tagname); 345 for (var i in elts) { 346 if ((elts[i].href && elts[i].href.toString().indexOf(fname) > 0) 347 || (elts[i].src && elts[i].src.toString().indexOf(fname) > 0)) { 348 BotionIsLoad = true; 349 } 350 } 351 } 352 return BotionIsLoad; 353}; 354window.initBotion = function (userConfig,callback) { 355 356 var config = new Config(userConfig); 357 if (userConfig.https) { 358 config.protocol = 'https://'; 359 } else if (!userConfig.protocol) { 360 config.protocol = window.location.protocol + '//'; 361 } 362 363 364 if (isObject(userConfig.getType)) { 365 config._extend(userConfig.getType); 366 } 367 368 jsonp(config.apiServers , config.typePath, config, function (newConfig) { 369 370 var newConfig = camelizeKeys(newConfig); 371 372 if(newConfig.status === 'error'){ 373 return throwError('networkError', config, newConfig); 374 } 375 376 var type = newConfig.type; 377 378 if(config.debug){ 379 new _Object(newConfig)._extend(config.debug) 380 } 381 var init = function () { 382 config._extend(newConfig); 383 callback(new window.Botion(config)); 384 }; 385 386 callbacks[type] = callbacks[type] || []; 387 388 var s = status[type] || 'init'; 389 if (s === 'init') { 390 391 status[type] = 'loading'; 392 393 callbacks[type].push(init); 394 395 if(newConfig.gctPath){ 396 load(config, config.protocol, Object.hasOwnProperty.call(config, 'staticServers') ? config.staticServers : newConfig.staticServers || config.staticServers , newConfig.gctPath, null, function (err){ 397 if(err){ 398 throwError('networkError', config, { 399 code: '60205', 400 msg: 'Network failure', 401 desc: { 402 detail: 'gct resource load timeout' 403 } 404 }); 405 } 406 }) 407 } 408 409 load(config, config.protocol, Object.hasOwnProperty.call(config, 'staticServers') ? config.staticServers : newConfig.staticServers || config.staticServers, newConfig.bypass || (newConfig.staticPath + newConfig.js), null, function (err) { 410 if (err) { 411 status[type] = 'fail'; 412 throwError('networkError', config, { 413 code: '60204', 414 msg: 'Network failure', 415 desc: { 416 detail: 'js resource load timeout' 417 } 418 }); 419 } else { 420 status[type] = 'loaded'; 421 var cbs = callbacks[type]; 422 for (var i = 0, len = cbs.length; i < len; i = i + 1) { 423 var cb = cbs[i]; 424 if (isFunction(cb)) { 425 cb(); 426 } 427 } 428 callbacks[type] = []; 429 } 430 }); 431 } else if (s === "loaded") { 432 if(!BotionIsLoad(newConfig.gctPath)){ 433 load(config, config.protocol, Object.hasOwnProperty.call(config, 'staticServers') ? config.staticServers : newConfig.staticServers || config.staticServers , newConfig.gctPath, null, function (err){ 434 if(err){ 435 throwError('networkError', config, { 436 code: '60205', 437 msg: 'Network failure', 438 desc: { 439 detail: 'gct resource load timeout' 440 } 441 }); 442 } 443 }) 444 } 445 return init(); 446 } else if (s === "fail") { 447 throwError('networkError', config, { 448 code: '60204', 449 msg: 'Network failure', 450 desc: { 451 detail: 'js resource load timeout' 452 } 453 }); 454 } else if (s === "loading") { 455 callbacks[type].push(init); 456 } 457 }); 458 459}; 460 461 462})(window);
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.