PageSourceSearch

https://2bra365.vip/static/js/gt4.js

js 2bra365.vip collected 2026-10-09 04:36:31 UTC 14,428 bytes, 522 lines download raw bytes

1/* eslint-disable */
2
3'v4.1.8 Geetest Inc.';
4
5(function (window) {
6  'use strict';
7  if (typeof window === 'undefined') {
8    throw new Error('Geetest requires browser environment');
9  }
10
11  var document = window.document;
12  var Math = window.Math;
13  var head = document.getElementsByTagName('head')[0];
14  var TIMEOUT = 10000;
15
16  function _Object(obj) {
17    this._obj = obj;
18  }
19
20  _Object.prototype = {
21    _each: function (process) {
22      var _obj = this._obj;
23      for (var k in _obj) {
24        if (_obj.hasOwnProperty(k)) {
25          process(k, _obj[k]);
26        }
27      }
28      return this;
29    },
30    _extend: function (obj) {
31      var self = this;
32      new _Object(obj)._each(function (key, value) {
33        self._obj[key] = value;
34      });
35    },
36  };
37
38  var uuid = function () {
39    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
40      var r = (Math.random() * 16) | 0;
41      var v = c === 'x' ? r : (r & 0x3) | 0x8;
42      return v.toString(16);
43    });
44  };
45
46  function Config(config) {
47    var self = this;
48    new _Object(config)._each(function (key, value) {
49      self[key] = value;
50    });
51  }
52
53  Config.prototype = {
54    apiServers: ['gcaptcha4.geetest.com', 'gcaptcha4.geevisit.com', 'gcaptcha4.gsensebot.com'],
55    staticServers: ['static.geetest.com', 'static.geevisit.com'],
56    protocol: 'http://',
57    typePath: '/load',
58    fallback_config: {
59      bypass: {
60        staticServers: ['static.geetest.com', 'static.geevisit.com'],
61        type: 'bypass',
62        bypass: '/v4/bypass.js',
63      },
64    },
65    _get_fallback_config: function () {
66      var self = this;
67      if (isString(self.type)) {
68        return self.fallback_config[self.type];
69      } else {
70        return self.fallback_config.bypass;
71      }
72    },
73    _extend: function (obj) {
74      var self = this;
75      new _Object(obj)._each(function (key, value) {
76        self[key] = value;
77      });
78    },
79  };
80  var isNumber = function (value) {
81    return typeof value === 'number';
82  };
83  var isString = function (value) {
84    return typeof value === 'string';
85  };
86  var isBoolean = function (value) {
87    return typeof value === 'boolean';
88  };
89  var isObject = function (value) {
90    return typeof value === 'object' && value !== null;
91  };
92  var isFunction = function (value) {
93    return typeof value === 'function';
94  };
95  var MOBILE = /Mobi/i.test(navigator.userAgent);
96
97  var callbacks = {};
98  var status = {};
99
100  var random = function () {
101    return parseInt(Math.random() * 10000) + new Date().valueOf();
102  };
103
104  // bind 函数polify, 不带new功能的bind
105
106  var bind = function (target, context) {
107    if (typeof target !== 'function') {
108      return;
109    }
110    var args = Array.prototype.slice.call(arguments, 2);
111
112    if (Function.prototype.bind) {
113      return target.bind(context, args);
114    } else {
115      return function () {
116        var _args = Array.prototype.slice.call(arguments);
117        return target.apply(context, args.concat(_args));
118      };
119    }
120  };
121
122  var toString = Object.prototype.toString;
123
124  var _isFunction = function (obj) {
125    return typeof obj === 'function';
126  };
127  var _isObject = function (obj) {
128    return obj === Object(obj);
129  };
130  var _isArray = function (obj) {
131    return toString.call(obj) == '[object Array]';
132  };
133  var _isDate = function (obj) {
134    return toString.call(obj) == '[object Date]';
135  };
136  var _isRegExp = function (obj) {
137    return toString.call(obj) == '[object RegExp]';
138  };
139  var _isBoolean = function (obj) {
140    return toString.call(obj) == '[object Boolean]';
141  };
142
143  function resolveKey(input) {
144    return input.replace(/(\S)(_([a-zA-Z]))/g, function (match, $1, $2, $3) {
145      return $1 + $3.toUpperCase() || '';
146    });
147  }
148
149  function 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    } else {
160      var temp = {};
161      for (var prop in input) {
162        if (input.hasOwnProperty(prop)) {
163          temp[camelizeKeys(prop, true)] = camelizeKeys(input[prop]);
164        }
165      }
166    }
167    return temp;
168  }
169
170  var loadScript = function (url, cb, timeout) {
171    var script = document.createElement('script');
172    script.charset = 'UTF-8';
173    script.async = true;
174
175    // 对geetest的静态资源添加 crossOrigin
176    if (/static\.geetest\.com/g.test(url)) {
177      script.crossOrigin = 'anonymous';
178    }
179
180    script.onerror = function () {
181      cb(true);
182      // 错误触发了,超时逻辑就不用了
183      loaded = true;
184    };
185    var loaded = false;
186    script.onload = script.onreadystatechange = function () {
187      if (!loaded && (!script.readyState || 'loaded' === script.readyState || 'complete' === script.readyState)) {
188        loaded = true;
189        setTimeout(function () {
190          cb(false);
191        }, 0);
192      }
193    };
194    script.src = url;
195    head.appendChild(script);
196
197    setTimeout(function () {
198      if (!loaded) {
199        script.onerror = script.onload = null;
200        script.remove && script.remove();
201        cb(true);
202      }
203    }, timeout || TIMEOUT);
204  };
205
206  var normalizeDomain = function (domain) {
207    // special domain: uems.sysu.edu.cn/jwxt/geetest/
208    // return domain.replace(/^https?:\/\/|\/.*$/g, ''); uems.sysu.edu.cn
209    return domain.replace(/^https?:\/\/|\/$/g, ''); // uems.sysu.edu.cn/jwxt/geetest
210  };
211  var normalizePath = function (path) {
212    path = path && path.replace(/\/+/g, '/');
213    if (path.indexOf('/') !== 0) {
214      path = '/' + path;
215    }
216    return path;
217  };
218  var normalizeQuery = function (query) {
219    if (!query) {
220      return '';
221    }
222    var q = '?';
223    new _Object(query)._each(function (key, value) {
224      if (isString(value) || isNumber(value) || isBoolean(value)) {
225        q = q + encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&';
226      }
227    });
228    if (q === '?') {
229      q = '';
230    }
231    return q.replace(/&$/, '');
232  };
233  var makeURL = function (protocol, domain, path, query) {
234    domain = normalizeDomain(domain);
235
236    var url = normalizePath(path) + normalizeQuery(query);
237    if (domain) {
238      url = protocol + domain + url;
239    }
240
241    return url;
242  };
243
244  var load = function (config, protocol, domains, path, query, cb, handleCb) {
245    var tryRequest = function (at) {
246      // 处理jsonp回调,这里为了保证每个不同jsonp都有唯一的回调函数
247      if (handleCb) {
248        var cbName = 'geetest_' + random();
249        // 需要与预先定义好cbname参数,删除对象
250        window[cbName] = bind(handleCb, null, cbName);
251        query.callback = cbName;
252      }
253      var url = makeURL(protocol, domains[at], path, query);
254      loadScript(
255        url,
256        function (err) {
257          if (err) {
258            // 超时或者出错的时候 移除回调
259            if (cbName) {
260              try {
261                window[cbName] = function () {
262                  window[cbName] = null;
263                };
264              } catch (e) {}
265            }
266
267            if (at >= domains.length - 1) {
268              cb(true);
269              // report gettype error
270            } else {
271              tryRequest(at + 1);
272            }
273          } else {
274            cb(false);
275          }
276        },
277        config.timeout,
278      );
279    };
280    tryRequest(0);
281  };
282
283  var jsonp = function (domains, path, config, callback) {
284    var handleCb = function (cbName, data) {
285      // 保证只执行一次,全部超时的情况下不会再触发;
286
287      if (data.status == 'success') {
288        callback(data.data);
289      } else if (!data.status) {
290        callback(data);
291      } else {
292        //接口有返回,但是返回了错误状态,进入报错逻辑
293        callback(data);
294      }
295      window[cbName] = undefined;
296      try {
297        delete window[cbName];
298      } catch (e) {}
299    };
300    load(
301      config,
302      config.protocol,
303      domains,
304      path,
305      {
306        callback: '',
307        captcha_id: config.captchaId,
308        challenge: config.challenge || uuid(),
309        client_type: MOBILE ? 'h5' : 'web',
310        risk_type: config.riskType,
311        user_info: config.userInfo,
312        call_type: config.callType,
313        lang: config.language
314          ? config.language
315          : navigator.appName === 'Netscape'
316            ? navigator.language.toLowerCase()
317            : navigator.userLanguage.toLowerCase(),
318      },
319      function (err) {
320        // 网络问题接口没有返回,直接使用本地验证码,走宕机模式
321        // 这里可以添加用户的逻辑
322        if (err && typeof config.offlineCb === 'function') {
323          // 执行自己的宕机
324          config.offlineCb();
325          return;
326        }
327        if (err) {
328          callback(config._get_fallback_config());
329        }
330      },
331      handleCb,
332    );
333  };
334
335  var reportError = function (config, url) {
336    load(
337      config,
338      config.protocol,
339      ['monitor.geetest.com'],
340      '/monitor/send',
341      {
342        time: Date.now().getTime(),
343        captcha_id: config.gt,
344        challenge: config.challenge,
345        exception_url: url,
346        error_code: config.error_code,
347      },
348      function (err) {},
349    );
350  };
351
352  var throwError = function (errorType, config, errObj) {
353    var errors = {
354      networkError: '网络错误',
355      gtTypeError: 'gt字段不是字符串类型',
356    };
357    if (typeof config.onError === 'function') {
358      config.onError({
359        desc: errObj.desc,
360        msg: errObj.msg,
361        code: errObj.code,
362      });
363    } else {
364      throw new Error(errors[errorType]);
365    }
366  };
367
368  var detect = function () {
369    return window.Geetest || document.getElementById('gt_lib');
370  };
371
372  if (detect()) {
373    status.slide = 'loaded';
374  }
375  var GeetestIsLoad = function (fname) {
376    var GeetestIsLoad = false;
377    var tags = { js: 'script', css: 'link' };
378    var tagname = fname && tags[fname.split('.').pop()];
379    if (tagname !== undefined) {
380      var elts = document.getElementsByTagName(tagname);
381      for (var i in elts) {
382        if (
383          (elts[i].href && elts[i].href.toString().indexOf(fname) > 0) ||
384          (elts[i].src && elts[i].src.toString().indexOf(fname) > 0)
385        ) {
386          GeetestIsLoad = true;
387        }
388      }
389    }
390    return GeetestIsLoad;
391  };
392  window.initGeetest4 = function (userConfig, callback) {
393    var config = new Config(userConfig);
394    if (userConfig.https) {
395      config.protocol = 'https://';
396    } else if (!userConfig.protocol) {
397      config.protocol = window.location.protocol + '//';
398    }
399
400    if (isObject(userConfig.getType)) {
401      config._extend(userConfig.getType);
402    }
403
404    jsonp(config.apiServers, config.typePath, config, function (newConfig) {
405      //错误捕获,第一个load请求可能直接报错
406      var newConfig = camelizeKeys(newConfig);
407
408      if (newConfig.status === 'error') {
409        return throwError('networkError', config, newConfig);
410      }
411
412      var type = newConfig.type;
413      if (config.debug) {
414        new _Object(newConfig)._extend(config.debug);
415      }
416      var init = function () {
417        config._extend(newConfig);
418        callback(new window.Geetest4(config));
419      };
420
421      callbacks[type] = callbacks[type] || [];
422
423      var s = status[type] || 'init';
424      if (s === 'init') {
425        status[type] = 'loading';
426
427        callbacks[type].push(init);
428
429        if (newConfig.gctPath) {
430          load(
431            config,
432            config.protocol,
433            Object.hasOwnProperty.call(config, 'staticServers')
434              ? config.staticServers
435              : newConfig.staticServers || config.staticServers,
436            newConfig.gctPath,
437            null,
438            function (err) {
439              if (err) {
440                throwError('networkError', config, {
441                  code: '60205',
442                  msg: 'Network failure',
443                  desc: {
444                    detail: 'gct resource load timeout',
445                  },
446                });
447              }
448            },
449          );
450        }
451
452        load(
453          config,
454          config.protocol,
455          Object.hasOwnProperty.call(config, 'staticServers')
456            ? config.staticServers
457            : newConfig.staticServers || config.staticServers,
458          newConfig.bypass || newConfig.staticPath + newConfig.js,
459          null,
460          function (err) {
461            if (err) {
462              status[type] = 'fail';
463              throwError('networkError', config, {
464                code: '60204',
465                msg: 'Network failure',
466                desc: {
467                  detail: 'js resource load timeout',
468                },
469              });
470            } else {
471              status[type] = 'loaded';
472              var cbs = callbacks[type];
473              for (var i = 0, len = cbs.length; i < len; i = i + 1) {
474                var cb = cbs[i];
475                if (isFunction(cb)) {
476                  cb();
477                }
478              }
479              callbacks[type] = [];
480              status[type] = 'init';
481            }
482          },
483        );
484      } else if (s === 'loaded') {
485        // 判断gct是否需要重新加载
486        if (newConfig.gctPath && !GeetestIsLoad(newConfig.gctPath)) {
487          load(
488            config,
489            config.protocol,
490            Object.hasOwnProperty.call(config, 'staticServers')
491              ? config.staticServers
492              : newConfig.staticServers || config.staticServers,
493            newConfig.gctPath,
494            null,
495            function (err) {
496              if (err) {
497                throwError('networkError', config, {
498                  code: '60205',
499                  msg: 'Network failure',
500                  desc: {
501                    detail: 'gct resource load timeout',
502                  },
503                });
504              }
505            },
506          );
507        }
508        return init();
509      } else if (s === 'fail') {
510        throwError('networkError', config, {
511          code: '60204',
512          msg: 'Network failure',
513          desc: {
514            detail: 'js resource load timeout',
515          },
516        });
517      } else if (s === 'loading') {
518        callbacks[type].push(init);
519      }
520    });
521  };
522})(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.