hina-cloud-js-sdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.js +12 -0
- package/.gitlab-ci.yml +20 -0
- package/.history/build/hotAnalyse.min_20230803204057.js +1 -0
- package/.history/build/hotAnalyse.min_20230803204548.js +338 -0
- package/.history/build/hotAnalyse.min_20230803204555.js +1 -0
- package/.history/build/hotAnalyse.min_20230803204716.js +338 -0
- package/.history/build/hotAnalyse.min_20230803204818.js +1 -0
- package/.history/build/hotAnalyse.min_20230803205007.js +338 -0
- package/.history/build/hotAnalyse.min_20230803205018.js +1 -0
- package/.history/rollup.config_20230803204057.js +57 -0
- package/.history/rollup.config_20230804165355.js +57 -0
- package/babel.config.js +4 -0
- package/build/hina-sa.esm.min.js +1 -0
- package/build/hina-sa.min.js +1 -0
- package/build/hina.esm.min.js +1 -0
- package/build/hina.min.js +1 -0
- package/build/hotAnalyse.min.js +1 -0
- package/package.json +35 -0
- package/report.json +101 -0
- package/rollup.config.js +57 -0
- package/sdk.png +0 -0
- package/sonar-project.properties +3 -0
- package/src/hotAnalyse.js +465 -0
- package/src/monitor/performance-monitor/index.js +103 -0
- package/src/monitor/performance-monitor/web-vitals.js +1 -0
- package/src/pv-sdk/autoTrack.js +648 -0
- package/src/pv-sdk/http.js +425 -0
- package/src/pv-sdk/index.js +405 -0
- package/src/pv-sdk/plugin.js +610 -0
- package/src/pv-sdk/property.js +388 -0
- package/src/pv-sdk/utils.js +1894 -0
@@ -0,0 +1,1894 @@
|
|
1
|
+
// import CryptoJS from 'crypto'
|
2
|
+
|
3
|
+
let MAX_REFERRER_STRING_LENGTH = 2000;
|
4
|
+
let LIB_VERSION = "3.1.1";
|
5
|
+
|
6
|
+
let utmTypes = [
|
7
|
+
"utm_source",
|
8
|
+
"utm_medium",
|
9
|
+
"utm_campaign",
|
10
|
+
"utm_content",
|
11
|
+
"utm_term",
|
12
|
+
];
|
13
|
+
|
14
|
+
let searchTypes = [
|
15
|
+
"www.baidu.",
|
16
|
+
"m.baidu.",
|
17
|
+
"m.sm.cn",
|
18
|
+
"so.com",
|
19
|
+
"sogou.com",
|
20
|
+
"youdao.com",
|
21
|
+
"google.",
|
22
|
+
"yahoo.com/",
|
23
|
+
"bing.com/",
|
24
|
+
"ask.com/",
|
25
|
+
];
|
26
|
+
let socialTypes = [
|
27
|
+
"weibo.com",
|
28
|
+
"renren.com",
|
29
|
+
"kaixin001.com",
|
30
|
+
"douban.com",
|
31
|
+
"qzone.qq.com",
|
32
|
+
"zhihu.com",
|
33
|
+
"tieba.baidu.com",
|
34
|
+
"weixin.qq.com",
|
35
|
+
];
|
36
|
+
let searchKeywords = {
|
37
|
+
baidu: ["wd", "word", "kw", "keyword"],
|
38
|
+
google: "q",
|
39
|
+
bing: "q",
|
40
|
+
yahoo: "p",
|
41
|
+
sogou: ["query", "keyword"],
|
42
|
+
so: "q",
|
43
|
+
sm: "q",
|
44
|
+
};
|
45
|
+
|
46
|
+
let cookieTestName = "hinasdk_domain_test";
|
47
|
+
|
48
|
+
let slice = Array.prototype.slice;
|
49
|
+
let toString = Object.prototype.toString;
|
50
|
+
let nativeForEach = Array.prototype.forEach;
|
51
|
+
let hasOwnProperty = Object.prototype.hasOwnProperty;
|
52
|
+
|
53
|
+
let { location, screen, localStorage, history } = window;
|
54
|
+
|
55
|
+
// 日志打印 需要注入showLog
|
56
|
+
class Log {
|
57
|
+
static log() {
|
58
|
+
if (!this.showLog) {
|
59
|
+
return false;
|
60
|
+
}
|
61
|
+
if (this.showLog === true || this.showLog === "string") {
|
62
|
+
arguments[0] = _.formatJsonString(arguments[0]);
|
63
|
+
}
|
64
|
+
if (typeof console === "object" && console.log) {
|
65
|
+
try {
|
66
|
+
return console.log.apply(console, arguments);
|
67
|
+
} catch (e) {
|
68
|
+
console.log(arguments[0]);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
// 检查sdk参数
|
75
|
+
class SDKDebug {
|
76
|
+
static checkProtocolIsSame(url1, url2) {
|
77
|
+
try {
|
78
|
+
if (_.URL(url1).protocol !== _.URL(url2).protocol) {
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
} catch (error) {
|
82
|
+
Log.log("The _.URL method is not supported");
|
83
|
+
return false;
|
84
|
+
}
|
85
|
+
return true;
|
86
|
+
}
|
87
|
+
static checkServerUrl() {
|
88
|
+
if (!_.check.isString(this.serverUrl) || _.trim(this.serverUrl) === "") {
|
89
|
+
Log.log(
|
90
|
+
"当前 serverUrl 为空或不正确,只在控制台打印日志,network 中不会发数据,请配置正确的 server_url!"
|
91
|
+
);
|
92
|
+
return false;
|
93
|
+
} else if (
|
94
|
+
_.check.isString(this.serverUrl) &&
|
95
|
+
this.serverUrl !== "" &&
|
96
|
+
!this.checkProtocolIsSame(this.serverUrl, location.href)
|
97
|
+
) {
|
98
|
+
Log.log(
|
99
|
+
"SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。\n因为:1、https 下面发送 http 的图片请求会失败。2、http 页面使用 https + ajax 方式发数据,在 ie9 及以下会丢失数据。"
|
100
|
+
);
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
return true;
|
104
|
+
}
|
105
|
+
static checkAjax(url) {
|
106
|
+
if (url === this.serverUrl) {
|
107
|
+
return false;
|
108
|
+
}
|
109
|
+
if (
|
110
|
+
_.check.isString(url) &&
|
111
|
+
url !== "" &&
|
112
|
+
!this.checkProtocolIsSame(url, location.href)
|
113
|
+
) {
|
114
|
+
Log.log(
|
115
|
+
"SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为 http 页面使用 https + ajax 方式发数据,在 ie9 及以下会丢失数据。"
|
116
|
+
);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
let _ = {};
|
122
|
+
|
123
|
+
_.MAX_REFERRER_STRING_LENGTH = MAX_REFERRER_STRING_LENGTH;
|
124
|
+
_.LIB_VERSION = LIB_VERSION;
|
125
|
+
_.utmTypes = utmTypes;
|
126
|
+
_.searchTypes = searchTypes;
|
127
|
+
_.socialTypes = socialTypes;
|
128
|
+
_.searchKeywords = searchKeywords;
|
129
|
+
|
130
|
+
_.each = function (obj, iterator, context) {
|
131
|
+
if (obj === null) {
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
if (nativeForEach && obj.forEach === nativeForEach) {
|
135
|
+
obj.forEach(iterator, context);
|
136
|
+
} else if (obj.length === +obj.length) {
|
137
|
+
for (let i = 0, l = obj.length; i < l; i++) {
|
138
|
+
if (i in obj && iterator.call(context, obj[i], i, obj) === {}) {
|
139
|
+
return;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
} else {
|
143
|
+
for (let key in obj) {
|
144
|
+
if (hasOwnProperty.call(obj, key)) {
|
145
|
+
if (iterator.call(context, obj[key], key, obj) === {}) {
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
};
|
152
|
+
|
153
|
+
_.map = function (obj, iterator) {
|
154
|
+
let results = [];
|
155
|
+
if (obj == null) {
|
156
|
+
return results;
|
157
|
+
}
|
158
|
+
if (Array.prototype.map && obj.map === Array.prototype.map) {
|
159
|
+
return obj.map(iterator);
|
160
|
+
}
|
161
|
+
_.each(obj, function (value, index, list) {
|
162
|
+
results.push(iterator(value, index, list));
|
163
|
+
});
|
164
|
+
return results;
|
165
|
+
};
|
166
|
+
|
167
|
+
_.extend = function (obj) {
|
168
|
+
_.each(slice.call(arguments, 1), function (source) {
|
169
|
+
for (let prop in source) {
|
170
|
+
if (source[prop] !== void 0) {
|
171
|
+
obj[prop] = source[prop];
|
172
|
+
}
|
173
|
+
}
|
174
|
+
});
|
175
|
+
return obj;
|
176
|
+
};
|
177
|
+
|
178
|
+
_.indexOf = function (arr, target) {
|
179
|
+
let indexof = arr.indexOf;
|
180
|
+
if (indexof) {
|
181
|
+
return indexof.call(arr, target);
|
182
|
+
} else {
|
183
|
+
for (let i = 0; i < arr.length; i++) {
|
184
|
+
if (target === arr[i]) {
|
185
|
+
return i;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
return -1;
|
189
|
+
}
|
190
|
+
};
|
191
|
+
|
192
|
+
_.trim = function (str) {
|
193
|
+
return str.replace(/(^[\s\uFEFF\xA0]+)|([\s\uFEFF\xA0]+$)/g, "");
|
194
|
+
};
|
195
|
+
|
196
|
+
_.formatDate = function (d) {
|
197
|
+
function pad(n) {
|
198
|
+
return n < 10 ? "0" + n : n;
|
199
|
+
}
|
200
|
+
function padMilliseconds(n) {
|
201
|
+
if (n < 10) {
|
202
|
+
return "00" + n;
|
203
|
+
} else if (n < 100) {
|
204
|
+
return "0" + n;
|
205
|
+
} else {
|
206
|
+
return n;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
return (
|
210
|
+
d.getFullYear() +
|
211
|
+
"-" +
|
212
|
+
pad(d.getMonth() + 1) +
|
213
|
+
"-" +
|
214
|
+
pad(d.getDate()) +
|
215
|
+
" " +
|
216
|
+
pad(d.getHours()) +
|
217
|
+
":" +
|
218
|
+
pad(d.getMinutes()) +
|
219
|
+
":" +
|
220
|
+
pad(d.getSeconds()) +
|
221
|
+
"." +
|
222
|
+
padMilliseconds(d.getMilliseconds())
|
223
|
+
);
|
224
|
+
};
|
225
|
+
|
226
|
+
_.formatTimeZone = function (d, i) {
|
227
|
+
if (typeof i !== "number") return d;
|
228
|
+
let len = d.getTime();
|
229
|
+
let offset = d.getTimezoneOffset() * 60000;
|
230
|
+
let utcTime = len + offset;
|
231
|
+
return new Date(utcTime + 3600000 * i);
|
232
|
+
};
|
233
|
+
|
234
|
+
_.formatJsonString = function (obj) {
|
235
|
+
try {
|
236
|
+
return JSON.stringify(obj, null, 8);
|
237
|
+
} catch (e) {
|
238
|
+
return JSON.stringify(obj);
|
239
|
+
}
|
240
|
+
};
|
241
|
+
|
242
|
+
_.searchObjDate = function (o, i) {
|
243
|
+
if (_.check.isObject(o) || _.check.isArray(o)) {
|
244
|
+
_.each(o, function (a, b) {
|
245
|
+
if (_.check.isObject(a) || _.check.isArray(a)) {
|
246
|
+
_.searchObjDate(o[b], i);
|
247
|
+
} else {
|
248
|
+
if (_.check.isDate(a)) {
|
249
|
+
o[b] = _.formatDate(_.formatTimeZone(a, i));
|
250
|
+
}
|
251
|
+
}
|
252
|
+
});
|
253
|
+
}
|
254
|
+
};
|
255
|
+
|
256
|
+
_.paramType = function (param) {
|
257
|
+
return Object.prototype.toString
|
258
|
+
.call(param)
|
259
|
+
.replace("[object ", "")
|
260
|
+
.replace("]", "");
|
261
|
+
};
|
262
|
+
|
263
|
+
_.check = {
|
264
|
+
isUndefined: function (obj) {
|
265
|
+
return obj === void 0;
|
266
|
+
},
|
267
|
+
|
268
|
+
isObject: function (obj) {
|
269
|
+
return toString.call(obj) === "[object Object]" && obj !== null;
|
270
|
+
},
|
271
|
+
|
272
|
+
isEmptyObject: function (obj) {
|
273
|
+
if (_.check.isObject(obj)) {
|
274
|
+
for (let key in obj) {
|
275
|
+
if (hasOwnProperty.call(obj, key)) {
|
276
|
+
return false;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
return true;
|
280
|
+
}
|
281
|
+
return false;
|
282
|
+
},
|
283
|
+
|
284
|
+
isArray: function (obj) {
|
285
|
+
return toString.call(obj) === "[object Array]";
|
286
|
+
},
|
287
|
+
|
288
|
+
isString: function (obj) {
|
289
|
+
return toString.call(obj) === "[object String]";
|
290
|
+
},
|
291
|
+
|
292
|
+
isDate: function (obj) {
|
293
|
+
return toString.call(obj) === "[object Date]";
|
294
|
+
},
|
295
|
+
|
296
|
+
isNumber: function (obj) {
|
297
|
+
return toString.call(obj) === "[object Number]";
|
298
|
+
},
|
299
|
+
|
300
|
+
isBoolean: function (obj) {
|
301
|
+
return toString.call(obj) === "[object Boolean]";
|
302
|
+
},
|
303
|
+
|
304
|
+
isFunction: function (obj) {
|
305
|
+
if (!obj) {
|
306
|
+
return false;
|
307
|
+
}
|
308
|
+
let type = Object.prototype.toString.call(obj);
|
309
|
+
return type === "[object Function]" || type === "[object AsyncFunction]";
|
310
|
+
},
|
311
|
+
|
312
|
+
isJSONString: function (str) {
|
313
|
+
try {
|
314
|
+
JSON.parse(str);
|
315
|
+
} catch (e) {
|
316
|
+
return false;
|
317
|
+
}
|
318
|
+
return true;
|
319
|
+
},
|
320
|
+
|
321
|
+
isElement: function (arg) {
|
322
|
+
return !!(arg && arg.nodeType === 1);
|
323
|
+
},
|
324
|
+
};
|
325
|
+
|
326
|
+
_.UUID = (function () {
|
327
|
+
let T = function () {
|
328
|
+
let d = 1 * new Date();
|
329
|
+
let i = 0;
|
330
|
+
while (d === 1 * new Date()) {
|
331
|
+
i++;
|
332
|
+
}
|
333
|
+
return d.toString(16) + i.toString(16);
|
334
|
+
};
|
335
|
+
let R = function () {
|
336
|
+
return Math.random().toString(16).replace(".", "");
|
337
|
+
};
|
338
|
+
let UA = function () {
|
339
|
+
let ua = navigator.userAgent;
|
340
|
+
let i;
|
341
|
+
let ch;
|
342
|
+
let buffer = [];
|
343
|
+
let ret = 0;
|
344
|
+
function xor(result, byteArray) {
|
345
|
+
let j;
|
346
|
+
let tmp = 0;
|
347
|
+
for (j = 0; j < byteArray.length; j++) {
|
348
|
+
tmp |= buffer[j] << (j * 8);
|
349
|
+
}
|
350
|
+
return result ^ tmp;
|
351
|
+
}
|
352
|
+
for (i = 0; i < ua.length; i++) {
|
353
|
+
ch = ua.charCodeAt(i);
|
354
|
+
buffer.unshift(ch & 0xff);
|
355
|
+
if (buffer.length >= 4) {
|
356
|
+
ret = xor(ret, buffer);
|
357
|
+
buffer = [];
|
358
|
+
}
|
359
|
+
}
|
360
|
+
if (buffer.length > 0) {
|
361
|
+
ret = xor(ret, buffer);
|
362
|
+
}
|
363
|
+
return ret.toString(16);
|
364
|
+
};
|
365
|
+
return function () {
|
366
|
+
let se = String(screen.height * screen.width);
|
367
|
+
if (se && /\d{5,}/.test(se)) {
|
368
|
+
se = se.toString(16);
|
369
|
+
} else {
|
370
|
+
se = String(Math.random() * 31242)
|
371
|
+
.replace(".", "")
|
372
|
+
.slice(0, 8);
|
373
|
+
}
|
374
|
+
let val = T() + "-" + R() + "-" + UA() + "-" + se + "-" + T();
|
375
|
+
if (val) {
|
376
|
+
return val;
|
377
|
+
} else {
|
378
|
+
return (
|
379
|
+
String(Math.random()) +
|
380
|
+
String(Math.random()) +
|
381
|
+
String(Math.random())
|
382
|
+
).slice(2, 15);
|
383
|
+
}
|
384
|
+
};
|
385
|
+
})();
|
386
|
+
|
387
|
+
_.getReferrer = function (targetReferrer) {
|
388
|
+
let referrer = targetReferrer || document.referrer;
|
389
|
+
if (typeof referrer !== "string") {
|
390
|
+
return "referrer exception" + String(referrer);
|
391
|
+
}
|
392
|
+
if (referrer.indexOf("https://www.baidu.com/") === 0) {
|
393
|
+
referrer = referrer.split("?")[0];
|
394
|
+
}
|
395
|
+
referrer = referrer.slice(0, MAX_REFERRER_STRING_LENGTH);
|
396
|
+
return typeof referrer === "string" ? referrer : "";
|
397
|
+
};
|
398
|
+
|
399
|
+
_.getCookielDomain = function (hostname) {
|
400
|
+
hostname = hostname || location.hostname;
|
401
|
+
if (
|
402
|
+
!(
|
403
|
+
_.check.isString(hostname) &&
|
404
|
+
hostname.match(/^[a-zA-Z0-9\u4e00-\u9fa5\-\.]+$/)
|
405
|
+
)
|
406
|
+
) {
|
407
|
+
hostname = "";
|
408
|
+
}
|
409
|
+
|
410
|
+
let splitResult = hostname.split(".");
|
411
|
+
if (
|
412
|
+
_.check.isArray(splitResult) &&
|
413
|
+
splitResult.length >= 2 &&
|
414
|
+
!/^(\d+\.)+\d+$/.test(hostname)
|
415
|
+
) {
|
416
|
+
let domainStr = "." + splitResult.splice(splitResult.length - 1, 1);
|
417
|
+
while (splitResult.length > 0) {
|
418
|
+
domainStr =
|
419
|
+
"." + splitResult.splice(splitResult.length - 1, 1) + domainStr;
|
420
|
+
document.cookie = cookieTestName + "=true; path=/; domain=" + domainStr;
|
421
|
+
|
422
|
+
if (document.cookie.indexOf(cookieTestName + "=true") !== -1) {
|
423
|
+
let nowDate = new Date();
|
424
|
+
nowDate.setTime(nowDate.getTime() - 1000);
|
425
|
+
|
426
|
+
document.cookie =
|
427
|
+
cookieTestName +
|
428
|
+
"=true; expires=" +
|
429
|
+
nowDate.toGMTString() +
|
430
|
+
"; path=/; SameSite=Lax; domain=" +
|
431
|
+
domainStr;
|
432
|
+
|
433
|
+
return domainStr;
|
434
|
+
}
|
435
|
+
}
|
436
|
+
}
|
437
|
+
return "";
|
438
|
+
};
|
439
|
+
|
440
|
+
_.getCurrentDomain = function (url) {
|
441
|
+
let cookieDomain = _.getCookielDomain();
|
442
|
+
if (url === "" || cookieDomain === "") {
|
443
|
+
return "url解析失败";
|
444
|
+
} else {
|
445
|
+
return cookieDomain;
|
446
|
+
}
|
447
|
+
};
|
448
|
+
|
449
|
+
_.hashCode = function (str) {
|
450
|
+
if (typeof str !== "string") {
|
451
|
+
return 0;
|
452
|
+
}
|
453
|
+
let hash = 0;
|
454
|
+
let char = null;
|
455
|
+
if (str.length === 0) {
|
456
|
+
return hash;
|
457
|
+
}
|
458
|
+
for (let i = 0; i < str.length; i++) {
|
459
|
+
char = str.charCodeAt(i);
|
460
|
+
hash = (hash << 5) - hash + char;
|
461
|
+
hash = hash & hash;
|
462
|
+
}
|
463
|
+
return hash;
|
464
|
+
};
|
465
|
+
|
466
|
+
_.base64Decode = function (str) {
|
467
|
+
let arr = [];
|
468
|
+
try {
|
469
|
+
arr = _.map(atob(str).split(""), function (c) {
|
470
|
+
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
471
|
+
});
|
472
|
+
} catch (e) {
|
473
|
+
arr = [];
|
474
|
+
}
|
475
|
+
|
476
|
+
try {
|
477
|
+
return decodeURIComponent(arr.join(""));
|
478
|
+
} catch (e) {
|
479
|
+
return arr.join("");
|
480
|
+
}
|
481
|
+
};
|
482
|
+
|
483
|
+
_.base64Encode = function (str) {
|
484
|
+
let result = "";
|
485
|
+
try {
|
486
|
+
result = btoa(
|
487
|
+
encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
|
488
|
+
return String.fromCharCode("0x" + p1);
|
489
|
+
})
|
490
|
+
);
|
491
|
+
} catch (e) {
|
492
|
+
result = str;
|
493
|
+
}
|
494
|
+
return result;
|
495
|
+
};
|
496
|
+
|
497
|
+
_.decodeURIComponent = function (val) {
|
498
|
+
let result = "";
|
499
|
+
try {
|
500
|
+
result = decodeURIComponent(val);
|
501
|
+
} catch (e) {
|
502
|
+
result = val;
|
503
|
+
}
|
504
|
+
return result;
|
505
|
+
};
|
506
|
+
|
507
|
+
_.encodeURIComponent = function (val) {
|
508
|
+
let result = "";
|
509
|
+
try {
|
510
|
+
result = encodeURIComponent(val);
|
511
|
+
} catch (e) {
|
512
|
+
result = val;
|
513
|
+
}
|
514
|
+
return result;
|
515
|
+
};
|
516
|
+
|
517
|
+
_.cookie = {
|
518
|
+
get: function (name) {
|
519
|
+
let nameEQ = name + "=";
|
520
|
+
let ca = document.cookie.split(";");
|
521
|
+
for (let i = 0; i < ca.length; i++) {
|
522
|
+
let c = ca[i];
|
523
|
+
while (c.charAt(0) === " ") {
|
524
|
+
c = c.substring(1, c.length);
|
525
|
+
}
|
526
|
+
if (c.indexOf(nameEQ) === 0) {
|
527
|
+
return _.decodeURIComponent(c.substring(nameEQ.length, c.length));
|
528
|
+
}
|
529
|
+
}
|
530
|
+
return null;
|
531
|
+
},
|
532
|
+
|
533
|
+
set: function (
|
534
|
+
name,
|
535
|
+
value,
|
536
|
+
days,
|
537
|
+
cross_subdomain,
|
538
|
+
cookie_samesite,
|
539
|
+
is_secure,
|
540
|
+
domain
|
541
|
+
) {
|
542
|
+
let cdomain = domain,
|
543
|
+
expires = "",
|
544
|
+
secure = "",
|
545
|
+
samesite = "";
|
546
|
+
days = days == null ? 73000 : days;
|
547
|
+
|
548
|
+
if (days !== 0) {
|
549
|
+
let date = new Date();
|
550
|
+
if (String(days).slice(-1) === "s") {
|
551
|
+
date.setTime(date.getTime() + Number(String(days).slice(0, -1)) * 1000);
|
552
|
+
} else {
|
553
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
554
|
+
}
|
555
|
+
|
556
|
+
expires = "; expires=" + date.toGMTString();
|
557
|
+
}
|
558
|
+
if (_.check.isString(cookie_samesite) && cookie_samesite !== "") {
|
559
|
+
samesite = "; SameSite=" + cookie_samesite;
|
560
|
+
}
|
561
|
+
if (is_secure) {
|
562
|
+
secure = "; secure";
|
563
|
+
}
|
564
|
+
|
565
|
+
function getValid(data) {
|
566
|
+
if (data) {
|
567
|
+
return data.replace(/\r\n/g, "");
|
568
|
+
} else {
|
569
|
+
return false;
|
570
|
+
}
|
571
|
+
}
|
572
|
+
let valid_name = "";
|
573
|
+
let valid_value = "";
|
574
|
+
let valid_domain = "";
|
575
|
+
if (name) {
|
576
|
+
valid_name = getValid(name);
|
577
|
+
}
|
578
|
+
if (value && _.check.isString(value)) {
|
579
|
+
valid_value = getValid(value);
|
580
|
+
} else {
|
581
|
+
valid_value = value;
|
582
|
+
}
|
583
|
+
if (cdomain) {
|
584
|
+
valid_domain = getValid(cdomain);
|
585
|
+
}
|
586
|
+
if (valid_name && valid_value) {
|
587
|
+
document.cookie =
|
588
|
+
valid_name +
|
589
|
+
"=" +
|
590
|
+
encodeURIComponent(valid_value) +
|
591
|
+
expires +
|
592
|
+
"; path=/" +
|
593
|
+
valid_domain +
|
594
|
+
samesite +
|
595
|
+
secure;
|
596
|
+
}
|
597
|
+
},
|
598
|
+
remove: function (name, cross_subdomain) {
|
599
|
+
this.set(name, "1", -1, cross_subdomain);
|
600
|
+
},
|
601
|
+
isSupport: function (testKey, testValue) {
|
602
|
+
testKey = testKey || "cookie_support_test";
|
603
|
+
testValue = testValue || "1";
|
604
|
+
let self = this;
|
605
|
+
|
606
|
+
function accessNormal() {
|
607
|
+
self.set(testKey, testValue);
|
608
|
+
let val = self.get(testKey);
|
609
|
+
if (val !== testValue) return false;
|
610
|
+
self.remove(testKey);
|
611
|
+
return true;
|
612
|
+
}
|
613
|
+
return navigator.cookieEnabled && accessNormal();
|
614
|
+
},
|
615
|
+
};
|
616
|
+
|
617
|
+
_.localStorage = {
|
618
|
+
get: function (key) {
|
619
|
+
return localStorage.getItem(key);
|
620
|
+
},
|
621
|
+
parse: function (key) {
|
622
|
+
let storedValue;
|
623
|
+
try {
|
624
|
+
storedValue = JSON.parse(_.localStorage.get(key)) || null;
|
625
|
+
} catch (err) {
|
626
|
+
Log.log("parse localStorage failed");
|
627
|
+
}
|
628
|
+
return storedValue;
|
629
|
+
},
|
630
|
+
set: function (key, value) {
|
631
|
+
try {
|
632
|
+
localStorage.setItem(key, value);
|
633
|
+
} catch (err) {
|
634
|
+
Log.log("localStorage is not support");
|
635
|
+
}
|
636
|
+
},
|
637
|
+
remove: function (key) {
|
638
|
+
localStorage.removeItem(key);
|
639
|
+
},
|
640
|
+
isSupport: function () {
|
641
|
+
let supported = true;
|
642
|
+
try {
|
643
|
+
let supportName = "__localStorageSupport__";
|
644
|
+
let val = "testIsSupportStorage";
|
645
|
+
_.localStorage.set(supportName, val);
|
646
|
+
if (_.localStorage.get(supportName) !== val) {
|
647
|
+
supported = false;
|
648
|
+
}
|
649
|
+
_.localStorage.remove(supportName);
|
650
|
+
} catch (err) {
|
651
|
+
supported = false;
|
652
|
+
}
|
653
|
+
return supported;
|
654
|
+
},
|
655
|
+
key: function (key) {
|
656
|
+
localStorage.key(key);
|
657
|
+
},
|
658
|
+
length: localStorage.length,
|
659
|
+
};
|
660
|
+
|
661
|
+
_.memory = {
|
662
|
+
data: {},
|
663
|
+
get: function (name) {
|
664
|
+
let result = this.data[name];
|
665
|
+
if (_.check.isUndefined(result)) return null;
|
666
|
+
if (!_.check.isUndefined(result.expireTime)) {
|
667
|
+
if (result.expireTime < _.now()) {
|
668
|
+
return null;
|
669
|
+
}
|
670
|
+
return result.value;
|
671
|
+
}
|
672
|
+
return result;
|
673
|
+
},
|
674
|
+
set: function (name, value, expires) {
|
675
|
+
if (expires) {
|
676
|
+
let nowTime = _.now();
|
677
|
+
let expireTime;
|
678
|
+
// ns ==> n秒
|
679
|
+
if (String(expires).slice(-1) === "s") {
|
680
|
+
expireTime = nowTime + Number(String(expires).slice(0, -1)) * 1000;
|
681
|
+
} else {
|
682
|
+
// n ==> n天
|
683
|
+
expireTime = nowTime + expires * 24 * 60 * 60 * 1000;
|
684
|
+
}
|
685
|
+
this.data[name] = {
|
686
|
+
value: value,
|
687
|
+
expireTime: expireTime,
|
688
|
+
};
|
689
|
+
}
|
690
|
+
this.data[name] = value;
|
691
|
+
},
|
692
|
+
};
|
693
|
+
|
694
|
+
_.now = function () {
|
695
|
+
if (Date.now && _.check.isFunction(Date.now)) {
|
696
|
+
return Date.now();
|
697
|
+
}
|
698
|
+
return new Date().getTime();
|
699
|
+
};
|
700
|
+
|
701
|
+
// _.unique = function (arr) {
|
702
|
+
// let temp,
|
703
|
+
// n = [],
|
704
|
+
// o = {};
|
705
|
+
// for (let i = 0; i < arr.length; i++) {
|
706
|
+
// temp = arr[i];
|
707
|
+
// if (!(temp in o)) {
|
708
|
+
// o[temp] = true;
|
709
|
+
// n.push(temp);
|
710
|
+
// }
|
711
|
+
// }
|
712
|
+
// return n;
|
713
|
+
// };
|
714
|
+
|
715
|
+
_.getRandom = function () {
|
716
|
+
let today = new Date();
|
717
|
+
let seed = today.getTime();
|
718
|
+
let num = Math.floor(Math.random() * 1000000);
|
719
|
+
return seed + "_" + num;
|
720
|
+
};
|
721
|
+
|
722
|
+
_.safeJSONParse = function (str) {
|
723
|
+
let val = null;
|
724
|
+
try {
|
725
|
+
val = JSON.parse(str);
|
726
|
+
} catch (e) {
|
727
|
+
return str;
|
728
|
+
}
|
729
|
+
return val;
|
730
|
+
};
|
731
|
+
|
732
|
+
_.saveObjectVal = function (name, value, secretKey) {
|
733
|
+
if (!_.check.isString(value)) {
|
734
|
+
value = JSON.stringify(value);
|
735
|
+
}
|
736
|
+
if (secretKey) {
|
737
|
+
//加密
|
738
|
+
}
|
739
|
+
_.localStorage.set(name, value);
|
740
|
+
};
|
741
|
+
_.readObjectVal = function (name, secretKey) {
|
742
|
+
let value = _.localStorage.get(name);
|
743
|
+
if (!value) return null;
|
744
|
+
if (secretKey) {
|
745
|
+
//解密
|
746
|
+
}
|
747
|
+
return _.safeJSONParse(value);
|
748
|
+
};
|
749
|
+
|
750
|
+
_.stripEmptyProperties = function (p) {
|
751
|
+
let ret = {};
|
752
|
+
_.each(p, function (v, k) {
|
753
|
+
if (_.check.isString(v) && v.length > 0) {
|
754
|
+
ret[k] = v;
|
755
|
+
}
|
756
|
+
});
|
757
|
+
return ret;
|
758
|
+
};
|
759
|
+
|
760
|
+
// 获取预置属性
|
761
|
+
_.info = {
|
762
|
+
os: function () {
|
763
|
+
let a = navigator.userAgent;
|
764
|
+
if (/Windows/i.test(a)) {
|
765
|
+
if (/Phone/.test(a) || /WPDesktop/.test(a)) {
|
766
|
+
return "Windows Phone";
|
767
|
+
}
|
768
|
+
return "Windows";
|
769
|
+
} else if (/(iPhone|iPad|iPod)/.test(a) && !window.MSStream) {
|
770
|
+
return "iOS";
|
771
|
+
} else if (/Android/.test(a)) {
|
772
|
+
return "Android";
|
773
|
+
} else if (/(BlackBerry|PlayBook|BB10)/i.test(a)) {
|
774
|
+
return "BlackBerry";
|
775
|
+
} else if (/Mac/i.test(a)) {
|
776
|
+
return "Mac OS X";
|
777
|
+
} else if (/Linux/.test(a)) {
|
778
|
+
return "Linux";
|
779
|
+
} else if (/CrOS/.test(a)) {
|
780
|
+
return "Chrome OS";
|
781
|
+
} else {
|
782
|
+
return "";
|
783
|
+
}
|
784
|
+
},
|
785
|
+
browser: function () {
|
786
|
+
let browser = { type: "", version: "" };
|
787
|
+
try {
|
788
|
+
let ua = navigator.userAgent.toLowerCase();
|
789
|
+
let versionMatch = [];
|
790
|
+
if (ua.match(/baidubrowser/) !== null) {
|
791
|
+
browser["type"] = "baidu";
|
792
|
+
versionMatch.push(/baidubrowser\/([\d.]+)/);
|
793
|
+
} else if (ua.match(/bidubrowser/) !== null) {
|
794
|
+
browser["type"] = "baidu";
|
795
|
+
versionMatch.push(/bidubrowser\/([\d.]+)/);
|
796
|
+
} else if (ua.match(/edga/) !== null) {
|
797
|
+
browser["type"] = "edge";
|
798
|
+
versionMatch.push(/edga\/([\d.]+)/);
|
799
|
+
} else if (ua.match(/edgios/) !== null) {
|
800
|
+
browser["type"] = "edge";
|
801
|
+
versionMatch.push(/edgios\/([\d.]+)/);
|
802
|
+
} else if (ua.match(/liebaofast/) !== null) {
|
803
|
+
browser["type"] = "liebao";
|
804
|
+
versionMatch.push(/liebaofast\/([\d.]+)/);
|
805
|
+
} else if (ua.match(/sogoumobilebrowser/) !== null) {
|
806
|
+
browser["type"] = "sogou";
|
807
|
+
versionMatch.push(/sogoumobilebrowser\/([\d.]+)/);
|
808
|
+
} else if (ua.match(/lbbrowser/) !== null) {
|
809
|
+
browser["type"] = "liebao";
|
810
|
+
versionMatch.push(/lbbrowser\/([\d.]+)/);
|
811
|
+
} else if (ua.match(/crios/) !== null) {
|
812
|
+
browser["type"] = "chrome";
|
813
|
+
versionMatch.push(/crios\/([\d.]+)/);
|
814
|
+
} else if (ua.match(/qihoobrowser/) !== null) {
|
815
|
+
browser["type"] = "360";
|
816
|
+
versionMatch.push(/qihoobrowser\/([\d.]+)/);
|
817
|
+
} else if (ua.match(/mxios/) !== null) {
|
818
|
+
browser["type"] = "maxthon";
|
819
|
+
versionMatch.push(/mxios\/([\d.]+)/);
|
820
|
+
} else if (ua.match(/fxios/) !== null) {
|
821
|
+
browser["type"] = "firefox";
|
822
|
+
versionMatch.push(/fxios\/([\d.\w]+)/);
|
823
|
+
} else if (ua.match(/edge/) !== null) {
|
824
|
+
browser["type"] = "edge";
|
825
|
+
versionMatch.push(/edge\/([\d.]+)/);
|
826
|
+
} else if (ua.match(/metasr/) !== null) {
|
827
|
+
browser["type"] = "sogou";
|
828
|
+
versionMatch.push(/metasr ([\d.]+)/);
|
829
|
+
} else if (ua.match(/micromessenger/) !== null) {
|
830
|
+
browser["type"] = "micromessenger";
|
831
|
+
versionMatch.push(/micromessenger\/([\d.]+)/);
|
832
|
+
} else if (ua.match(/mqqbrowser/) !== null) {
|
833
|
+
browser["type"] = "qq";
|
834
|
+
versionMatch.push(/mqqbrowser\/([\d.]+)/);
|
835
|
+
} else if (ua.match(/qqbrowserlite/) !== null) {
|
836
|
+
browser["type"] = "qq";
|
837
|
+
versionMatch.push(/qqbrowserlite\/([\d.]+)/);
|
838
|
+
} else if (ua.match(/tencenttraveler/) !== null) {
|
839
|
+
browser["type"] = "qq";
|
840
|
+
versionMatch.push(/tencenttraveler\/([\d.]+)/);
|
841
|
+
} else if (ua.match(/qqbrowser/) !== null) {
|
842
|
+
browser["type"] = "qq";
|
843
|
+
versionMatch.push(/qqbrowser\/([\d.]+)/);
|
844
|
+
} else if (ua.match(/maxthon/) !== null) {
|
845
|
+
browser["type"] = "maxthon";
|
846
|
+
versionMatch.push(/maxthon\/([\d.]+)/);
|
847
|
+
} else if (ua.match(/ubrowser/) !== null) {
|
848
|
+
browser["type"] = "uc";
|
849
|
+
versionMatch.push(/ubrowser\/([\d.]+)/);
|
850
|
+
} else if (ua.match(/ucbrowser/) !== null) {
|
851
|
+
browser["type"] = "uc";
|
852
|
+
versionMatch.push(/ucbrowser\/([\d.]+)/);
|
853
|
+
} else if (ua.match(/firefox/) !== null) {
|
854
|
+
browser["type"] = "firefox";
|
855
|
+
versionMatch.push(/firefox\/([\d.]+)/);
|
856
|
+
} else if (ua.match(/opera/) !== null) {
|
857
|
+
browser["type"] = "opera";
|
858
|
+
versionMatch.push(/opera\/([\d.]+)/);
|
859
|
+
} else if (ua.match(/opr/) !== null) {
|
860
|
+
browser["type"] = "opera";
|
861
|
+
versionMatch.push(/opr\/([\d.]+)/);
|
862
|
+
} else if (ua.match(/chrome/) !== null) {
|
863
|
+
browser["type"] = "chrome";
|
864
|
+
versionMatch.push(/chrome\/([\d.]+)/);
|
865
|
+
} else if (ua.match(/safari/) !== null) {
|
866
|
+
browser["type"] = "safari";
|
867
|
+
versionMatch.push(/version\/([\d.]+)/);
|
868
|
+
} else if (ua.match(/trident/) !== null || ua.match(/msie/) !== null) {
|
869
|
+
browser["type"] = "ie";
|
870
|
+
}
|
871
|
+
|
872
|
+
if (browser["type"] === "ie") {
|
873
|
+
let tridentVersion = ua.match(/trident\/([\d.]+)/)
|
874
|
+
? ua.match(/trident\/([\d.]+)/)[1]
|
875
|
+
: "";
|
876
|
+
let msieVersion = ua.match(/msie ([\d.]+)/)
|
877
|
+
? ua.match(/msie ([\d.]+)/)[1]
|
878
|
+
: "";
|
879
|
+
|
880
|
+
if (tridentVersion !== "") {
|
881
|
+
browser["version"] = String(parseInt(tridentVersion) + 4);
|
882
|
+
} else if (msieVersion !== "") {
|
883
|
+
browser["version"] = msieVersion;
|
884
|
+
}
|
885
|
+
} else if (versionMatch) {
|
886
|
+
browser["version"] = ua.match(versionMatch[0])
|
887
|
+
? ua.match(versionMatch[0])[1]
|
888
|
+
: "";
|
889
|
+
}
|
890
|
+
} catch (e) {
|
891
|
+
Log.w("getting browser info failed due to ", e);
|
892
|
+
}
|
893
|
+
return browser;
|
894
|
+
},
|
895
|
+
properties: function () {
|
896
|
+
let browserInfo = _.info.browser();
|
897
|
+
return _.extend({
|
898
|
+
H_os: _.info.os(),
|
899
|
+
H_lib_version: LIB_VERSION,
|
900
|
+
H_lib: "js",
|
901
|
+
H_screen_height: Number(screen.height) || 0,
|
902
|
+
H_screen_width: Number(screen.width) || 0,
|
903
|
+
H_browser: browserInfo.type,
|
904
|
+
H_browser_version: browserInfo.version,
|
905
|
+
H_system_language: _.check.isString(navigator.languages[1])
|
906
|
+
? navigator.languages[1].toLowerCase()
|
907
|
+
: "取值异常",
|
908
|
+
// H_ua: _.check.isString(navigator.userAgent)
|
909
|
+
// ? navigator.userAgent.toLowerCase()
|
910
|
+
// : "取值异常",
|
911
|
+
});
|
912
|
+
},
|
913
|
+
pageProperties: function () {
|
914
|
+
let referrer = _.getReferrer();
|
915
|
+
let url_domain = _.getCurrentDomain(location.href);
|
916
|
+
return _.stripEmptyProperties({
|
917
|
+
H_referrer: referrer,
|
918
|
+
H_referrer_host: referrer ? _.getHostname(referrer) : "",
|
919
|
+
H_url: location.href,
|
920
|
+
H_url_host: _.getHostname(location.url, "url_host取值异常"),
|
921
|
+
H_url_domain: url_domain,
|
922
|
+
H_url_path: location.pathname,
|
923
|
+
H_title: document.title,
|
924
|
+
});
|
925
|
+
},
|
926
|
+
getElementInfo: function (target, isCollectInputContent) {
|
927
|
+
if (!_.check.isElement(target)) return {};
|
928
|
+
let tagName = target.tagName.toLowerCase();
|
929
|
+
let props = {
|
930
|
+
H_element_type: tagName,
|
931
|
+
H_element_name: target.getAttribute("name"),
|
932
|
+
H_element_id: target.getAttribute("id"),
|
933
|
+
H_element_target_url: target.getAttribute("href"),
|
934
|
+
H_element_class_name: _.check.isString(target.className)
|
935
|
+
? target.className
|
936
|
+
: null,
|
937
|
+
H_element_content: _.getElementContent(
|
938
|
+
target,
|
939
|
+
tagName,
|
940
|
+
isCollectInputContent
|
941
|
+
),
|
942
|
+
};
|
943
|
+
|
944
|
+
return _.stripEmptyProperties(props);
|
945
|
+
},
|
946
|
+
};
|
947
|
+
|
948
|
+
_.getElementContent = function (
|
949
|
+
target,
|
950
|
+
tagName,
|
951
|
+
isCollectInputContent = false
|
952
|
+
) {
|
953
|
+
if (tagName === "input") {
|
954
|
+
if (["button", "submit"].includes(target.type) || isCollectInputContent) {
|
955
|
+
return target.value || "";
|
956
|
+
}
|
957
|
+
return "";
|
958
|
+
} else {
|
959
|
+
let textContent = "";
|
960
|
+
let elementContent = "";
|
961
|
+
if (target.textContent) {
|
962
|
+
textContent = _.trim(target.textContent);
|
963
|
+
} else if (target.innerText) {
|
964
|
+
textContent = _.trim(target.innerText);
|
965
|
+
}
|
966
|
+
if (textContent) {
|
967
|
+
textContent = textContent
|
968
|
+
.replace(/[\r\n]/g, " ")
|
969
|
+
.replace(/[ ]+/g, " ")
|
970
|
+
.substring(0, 255);
|
971
|
+
}
|
972
|
+
elementContent = textContent || "";
|
973
|
+
return elementContent;
|
974
|
+
}
|
975
|
+
};
|
976
|
+
|
977
|
+
_.getHostname = function (url, defaultValue) {
|
978
|
+
if (!defaultValue || typeof defaultValue !== "string") {
|
979
|
+
defaultValue = "hostname解析异常";
|
980
|
+
}
|
981
|
+
if (!url) {
|
982
|
+
return defaultValue;
|
983
|
+
}
|
984
|
+
let hostname = null;
|
985
|
+
try {
|
986
|
+
hostname = _.URL(url).hostname;
|
987
|
+
} catch (e) {
|
988
|
+
Log.log("getHostname传入的url参数不合法!");
|
989
|
+
}
|
990
|
+
return hostname || defaultValue;
|
991
|
+
};
|
992
|
+
|
993
|
+
_.isReferralTraffic = function (referrer) {
|
994
|
+
referrer = referrer || document.referrer;
|
995
|
+
if (referrer === "") {
|
996
|
+
return true;
|
997
|
+
}
|
998
|
+
|
999
|
+
return _.getCookielDomain(_.getHostname(referrer)) !== _.getCookielDomain();
|
1000
|
+
};
|
1001
|
+
|
1002
|
+
_.getUtm = function () {
|
1003
|
+
let params = {};
|
1004
|
+
_.each(utmTypes, function (kwkey) {
|
1005
|
+
let kw = _.getQueryParam(location.href, kwkey);
|
1006
|
+
if (kw.length) {
|
1007
|
+
params[kwkey] = kw;
|
1008
|
+
}
|
1009
|
+
});
|
1010
|
+
return params;
|
1011
|
+
};
|
1012
|
+
|
1013
|
+
_.getQueryParam = function (url, key) {
|
1014
|
+
key = key.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
1015
|
+
url = _.decodeURIComponent(url);
|
1016
|
+
let regexS = "[\\?&]" + key + "=([^&#]*)",
|
1017
|
+
regex = new RegExp(regexS),
|
1018
|
+
results = regex.exec(url);
|
1019
|
+
if (
|
1020
|
+
results === null ||
|
1021
|
+
(results && typeof results[1] !== "string" && results[1].length)
|
1022
|
+
) {
|
1023
|
+
return "";
|
1024
|
+
} else {
|
1025
|
+
return _.decodeURIComponent(results[1]);
|
1026
|
+
}
|
1027
|
+
};
|
1028
|
+
|
1029
|
+
//对称加密后续
|
1030
|
+
// _.createString = function (length) {
|
1031
|
+
// let expect = length;
|
1032
|
+
// let str = Math.random().toString(36).substr(2);
|
1033
|
+
// while (str.length < expect) {
|
1034
|
+
// str += Math.random().toString(36).substr(2);
|
1035
|
+
// }
|
1036
|
+
// str = str.substr(0, length);
|
1037
|
+
// return str;
|
1038
|
+
// };
|
1039
|
+
|
1040
|
+
// _.createAesKey = function () {
|
1041
|
+
// return _.createString(16);
|
1042
|
+
// };
|
1043
|
+
|
1044
|
+
// _.generateEncryptyData = function (text, secretKey) {
|
1045
|
+
|
1046
|
+
// if (typeof secretKey === 'undefined') {
|
1047
|
+
// return text;
|
1048
|
+
// }
|
1049
|
+
|
1050
|
+
// let pkey = secretKey['publicKey'];
|
1051
|
+
// let v = secretKey['version'];
|
1052
|
+
|
1053
|
+
// if (typeof pkey === 'undefined' || typeof v === 'undefined') {
|
1054
|
+
// return text;
|
1055
|
+
// }
|
1056
|
+
|
1057
|
+
// if (typeof CryptoJS === 'undefined' || typeof JSEncrypt === 'undefined') {
|
1058
|
+
// return text;
|
1059
|
+
// }
|
1060
|
+
// let strKey = _.createAesKey();
|
1061
|
+
// try {
|
1062
|
+
// let key = CryptoJS.enc.Utf8.parse(strKey);
|
1063
|
+
// let data = CryptoJS.enc.Utf8.parse(JSON.stringify(text));
|
1064
|
+
// let aesStr = CryptoJS.AES.encrypt(data, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString();
|
1065
|
+
// let encrypt = new JSEncrypt();
|
1066
|
+
// encrypt.setPublicKey(pkey);
|
1067
|
+
// let rsaStr = encrypt.encrypt(strKey);
|
1068
|
+
// if (rsaStr === false) {
|
1069
|
+
// Log.w('encryption failed');
|
1070
|
+
// return text;
|
1071
|
+
// }
|
1072
|
+
// return {
|
1073
|
+
// pkv: v,
|
1074
|
+
// ekey: rsaStr,
|
1075
|
+
// payload: aesStr
|
1076
|
+
// };
|
1077
|
+
// } catch (e) {
|
1078
|
+
// Log.w('encryption failed');
|
1079
|
+
// }
|
1080
|
+
// return text;
|
1081
|
+
// };
|
1082
|
+
|
1083
|
+
// dom相关
|
1084
|
+
class DomElementInfo {
|
1085
|
+
constructor(dom) {
|
1086
|
+
this.ele = dom;
|
1087
|
+
}
|
1088
|
+
|
1089
|
+
addClass(para) {
|
1090
|
+
let classes = " " + this.ele.className + " ";
|
1091
|
+
if (classes.indexOf(" " + para + " ") === -1) {
|
1092
|
+
this.ele.className =
|
1093
|
+
this.ele.className + (this.ele.className === "" ? "" : " ") + para;
|
1094
|
+
}
|
1095
|
+
return this;
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
removeClass(para) {
|
1099
|
+
let classes = " " + this.ele.className + " ";
|
1100
|
+
if (classes.indexOf(" " + para + " ") !== -1) {
|
1101
|
+
this.ele.className = classes.replace(" " + para + " ", " ").slice(1, -1);
|
1102
|
+
}
|
1103
|
+
return this;
|
1104
|
+
}
|
1105
|
+
|
1106
|
+
hasClass(para) {
|
1107
|
+
let classes = " " + this.ele.className + " ";
|
1108
|
+
if (classes.indexOf(" " + para + " ") !== -1) {
|
1109
|
+
return true;
|
1110
|
+
} else {
|
1111
|
+
return false;
|
1112
|
+
}
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
attr(key, value) {
|
1116
|
+
if (typeof key === "string" && _.check.isUndefined(value)) {
|
1117
|
+
return this.ele.getAttribute(key);
|
1118
|
+
}
|
1119
|
+
if (typeof key === "string") {
|
1120
|
+
value = String(value);
|
1121
|
+
this.ele.setAttribute(key, value);
|
1122
|
+
}
|
1123
|
+
return this;
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
offset() {
|
1127
|
+
let rect = this.ele.getBoundingClientRect();
|
1128
|
+
if (rect.width || rect.height) {
|
1129
|
+
let doc = this.ele.ownerDocument;
|
1130
|
+
let docElem = doc.documentElement;
|
1131
|
+
|
1132
|
+
return {
|
1133
|
+
top: rect.top + window.pageYOffset - docElem.clientTop,
|
1134
|
+
left: rect.left + window.pageXOffset - docElem.clientLeft,
|
1135
|
+
};
|
1136
|
+
} else {
|
1137
|
+
return {
|
1138
|
+
top: 0,
|
1139
|
+
left: 0,
|
1140
|
+
};
|
1141
|
+
}
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
getSize() {
|
1145
|
+
if (!window.getComputedStyle) {
|
1146
|
+
return {
|
1147
|
+
width: this.ele.offsetWidth,
|
1148
|
+
height: this.ele.offsetHeight,
|
1149
|
+
};
|
1150
|
+
}
|
1151
|
+
try {
|
1152
|
+
let bounds = this.ele.getBoundingClientRect();
|
1153
|
+
return {
|
1154
|
+
width: bounds.width,
|
1155
|
+
height: bounds.height,
|
1156
|
+
};
|
1157
|
+
} catch (e) {
|
1158
|
+
return {
|
1159
|
+
width: 0,
|
1160
|
+
height: 0,
|
1161
|
+
};
|
1162
|
+
}
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
getStyle(value) {
|
1166
|
+
if (this.ele.currentStyle) {
|
1167
|
+
return this.ele.currentStyle[value];
|
1168
|
+
} else {
|
1169
|
+
return this.ele.ownerDocument.defaultView
|
1170
|
+
.getComputedStyle(this.ele, null)
|
1171
|
+
.getPropertyValue(value);
|
1172
|
+
}
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
wrap(elementTagName) {
|
1176
|
+
let ele = document.createElement(elementTagName);
|
1177
|
+
this.ele.parentNode.insertBefore(ele, this.ele);
|
1178
|
+
ele.appendChild(this.ele);
|
1179
|
+
return _.getDomElementInfo(ele);
|
1180
|
+
}
|
1181
|
+
|
1182
|
+
getCssStyle(prop) {
|
1183
|
+
let result = this.ele.style.getPropertyValue(prop);
|
1184
|
+
if (result) {
|
1185
|
+
return result;
|
1186
|
+
}
|
1187
|
+
let rules = null;
|
1188
|
+
if (typeof window.getMatchedCSSRules === "function") {
|
1189
|
+
rules = window.getMatchedCSSRules(this.ele);
|
1190
|
+
}
|
1191
|
+
if (!rules || !_.check.isArray(rules)) {
|
1192
|
+
return null;
|
1193
|
+
}
|
1194
|
+
for (let i = rules.length - 1; i >= 0; i--) {
|
1195
|
+
let r = rules[i];
|
1196
|
+
result = r.style.getPropertyValue(prop);
|
1197
|
+
if (result) {
|
1198
|
+
return result;
|
1199
|
+
}
|
1200
|
+
}
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
sibling(cur, dir) {
|
1204
|
+
while ((cur = cur[dir]) && cur.nodeType !== 1) {}
|
1205
|
+
return cur;
|
1206
|
+
}
|
1207
|
+
|
1208
|
+
next() {
|
1209
|
+
return this.sibling(this.ele, "nextSibling");
|
1210
|
+
}
|
1211
|
+
prev() {
|
1212
|
+
return this.sibling(this.ele, "previousSibling");
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
siblingsFn(n, elem) {
|
1216
|
+
let matched = [];
|
1217
|
+
|
1218
|
+
for (; n; n = n.nextSibling) {
|
1219
|
+
if (n.nodeType === 1 && n !== elem) {
|
1220
|
+
matched.push(n);
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
return matched;
|
1225
|
+
}
|
1226
|
+
|
1227
|
+
siblings() {
|
1228
|
+
return this.siblingsFn((this.ele.parentNode || {}).firstChild, this.ele);
|
1229
|
+
}
|
1230
|
+
|
1231
|
+
children() {
|
1232
|
+
return this.siblingsFn(this.ele.firstChild);
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
parent() {
|
1236
|
+
let parent = this.ele.parentNode;
|
1237
|
+
parent = parent && parent.nodeType !== 11 ? parent : null;
|
1238
|
+
return _.getDomElementInfo(parent);
|
1239
|
+
}
|
1240
|
+
|
1241
|
+
previousElementSibling() {
|
1242
|
+
let el = this.ele;
|
1243
|
+
if ("previousElementSibling" in document.documentElement) {
|
1244
|
+
return _.getDomElementInfo(el.previousElementSibling);
|
1245
|
+
} else {
|
1246
|
+
while ((el = el.previousSibling)) {
|
1247
|
+
if (el.nodeType === 1) {
|
1248
|
+
return _.getDomElementInfo(el);
|
1249
|
+
}
|
1250
|
+
}
|
1251
|
+
return _.getDomElementInfo(null);
|
1252
|
+
}
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
getSameTypeSiblings() {
|
1256
|
+
let element = this.ele;
|
1257
|
+
let parentNode = element.parentNode;
|
1258
|
+
let tagName = element.tagName.toLowerCase();
|
1259
|
+
let arr = [];
|
1260
|
+
for (let i = 0; i < parentNode.children.length; i++) {
|
1261
|
+
let child = parentNode.children[i];
|
1262
|
+
if (child.nodeType === 1 && child.tagName.toLowerCase() === tagName) {
|
1263
|
+
arr.push(parentNode.children[i]);
|
1264
|
+
}
|
1265
|
+
}
|
1266
|
+
return arr;
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
getParents() {
|
1270
|
+
try {
|
1271
|
+
let element = this.ele;
|
1272
|
+
if (!_.check.isElement(element)) {
|
1273
|
+
return [];
|
1274
|
+
}
|
1275
|
+
let pathArr = [element];
|
1276
|
+
if (element === null || element.parentElement === null) {
|
1277
|
+
return [];
|
1278
|
+
}
|
1279
|
+
while (element.parentElement !== null) {
|
1280
|
+
element = element.parentElement;
|
1281
|
+
pathArr.push(element);
|
1282
|
+
}
|
1283
|
+
return pathArr;
|
1284
|
+
} catch (err) {
|
1285
|
+
return [];
|
1286
|
+
}
|
1287
|
+
}
|
1288
|
+
}
|
1289
|
+
|
1290
|
+
_.getDomElementInfo = function (dom) {
|
1291
|
+
return new DomElementInfo(dom);
|
1292
|
+
};
|
1293
|
+
|
1294
|
+
_.addEvent = function (target, eventName, eventHandler, useCapture) {
|
1295
|
+
function fixEvent(event) {
|
1296
|
+
if (event) {
|
1297
|
+
event.preventDefault = fixEvent.preventDefault;
|
1298
|
+
event.stopPropagation = fixEvent.stopPropagation;
|
1299
|
+
event._getPath = fixEvent._getPath;
|
1300
|
+
}
|
1301
|
+
return event;
|
1302
|
+
}
|
1303
|
+
fixEvent._getPath = function () {
|
1304
|
+
let ev = this;
|
1305
|
+
return this.path || _.getDomElementInfo(ev.target).getParents();
|
1306
|
+
};
|
1307
|
+
|
1308
|
+
fixEvent.preventDefault = function () {
|
1309
|
+
this.returnValue = false;
|
1310
|
+
};
|
1311
|
+
fixEvent.stopPropagation = function () {
|
1312
|
+
this.cancelBubble = true;
|
1313
|
+
};
|
1314
|
+
|
1315
|
+
let registerEvent = function (element, type, handler) {
|
1316
|
+
if (useCapture === undefined && type === "click") {
|
1317
|
+
useCapture = true;
|
1318
|
+
}
|
1319
|
+
if (element && element.addEventListener) {
|
1320
|
+
element.addEventListener(
|
1321
|
+
type,
|
1322
|
+
function (e) {
|
1323
|
+
e._getPath = fixEvent._getPath;
|
1324
|
+
handler.call(this, e);
|
1325
|
+
},
|
1326
|
+
useCapture
|
1327
|
+
);
|
1328
|
+
} else {
|
1329
|
+
let ontype = "on" + type;
|
1330
|
+
let old_handler = element[ontype];
|
1331
|
+
element[ontype] = makeHandler(element, handler, old_handler, type);
|
1332
|
+
}
|
1333
|
+
};
|
1334
|
+
|
1335
|
+
function makeHandler(element, new_handler, old_handlers, type) {
|
1336
|
+
let handler = function (event) {
|
1337
|
+
event = event || fixEvent(window.event);
|
1338
|
+
if (!event) {
|
1339
|
+
return undefined;
|
1340
|
+
}
|
1341
|
+
event.target = event.srcElement;
|
1342
|
+
|
1343
|
+
let ret = true;
|
1344
|
+
let old_result, new_result;
|
1345
|
+
if (typeof old_handlers === "function") {
|
1346
|
+
old_result = old_handlers(event);
|
1347
|
+
}
|
1348
|
+
new_result = new_handler.call(element, event);
|
1349
|
+
if (type !== "beforeunload") {
|
1350
|
+
if (false === old_result || false === new_result) {
|
1351
|
+
ret = false;
|
1352
|
+
}
|
1353
|
+
return ret;
|
1354
|
+
}
|
1355
|
+
};
|
1356
|
+
return handler;
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
registerEvent.apply(null, arguments);
|
1360
|
+
};
|
1361
|
+
|
1362
|
+
_.addCaptureEvent = function (target, eventName, eventHandler) {
|
1363
|
+
return this.addEvent(target, eventName, eventHandler, eventName === "click");
|
1364
|
+
};
|
1365
|
+
|
1366
|
+
// 是否存在死循环引用
|
1367
|
+
_.hasCircularReference = function (obj, seen = new Set()) {
|
1368
|
+
if (typeof obj !== "object" || obj === null) {
|
1369
|
+
return false;
|
1370
|
+
}
|
1371
|
+
|
1372
|
+
if (seen.has(obj)) {
|
1373
|
+
return true;
|
1374
|
+
}
|
1375
|
+
|
1376
|
+
seen.add(obj);
|
1377
|
+
|
1378
|
+
for (let key in obj) {
|
1379
|
+
if (_.hasCircularReference(obj[key], seen)) {
|
1380
|
+
return true;
|
1381
|
+
}
|
1382
|
+
}
|
1383
|
+
|
1384
|
+
seen.delete(obj);
|
1385
|
+
|
1386
|
+
return false;
|
1387
|
+
};
|
1388
|
+
|
1389
|
+
_.parseSuperProperties = function (props) {
|
1390
|
+
let data = props.properties || {};
|
1391
|
+
let copyProps = JSON.parse(JSON.stringify(props));
|
1392
|
+
if (_.check.isObject(data)) {
|
1393
|
+
_.each(data, function (value, key) {
|
1394
|
+
if (_.check.isFunction(value)) {
|
1395
|
+
try {
|
1396
|
+
data[key] = value(copyProps);
|
1397
|
+
if (_.check.isFunction(data[key])) {
|
1398
|
+
Log.log("属性--" + key + " 格式不满足要求, 已被删除");
|
1399
|
+
delete data[key];
|
1400
|
+
}
|
1401
|
+
} catch (error) {
|
1402
|
+
delete data[key];
|
1403
|
+
Log.log("属性--" + key + " 格式不满足要求, 已被删除");
|
1404
|
+
}
|
1405
|
+
}
|
1406
|
+
});
|
1407
|
+
}
|
1408
|
+
};
|
1409
|
+
|
1410
|
+
_.getURLSearchParams = function (queryString) {
|
1411
|
+
queryString = queryString || "";
|
1412
|
+
let args = {};
|
1413
|
+
let query = queryString.substring(1);
|
1414
|
+
let pairs = query.split("&");
|
1415
|
+
for (let i = 0; i < pairs.length; i++) {
|
1416
|
+
let pos = pairs[i].indexOf("=");
|
1417
|
+
if (pos === -1) continue;
|
1418
|
+
let name = pairs[i].substring(0, pos);
|
1419
|
+
let value = pairs[i].substring(pos + 1);
|
1420
|
+
name = _.decodeURIComponent(name);
|
1421
|
+
value = _.decodeURIComponent(value);
|
1422
|
+
args[name] = value;
|
1423
|
+
}
|
1424
|
+
return args;
|
1425
|
+
};
|
1426
|
+
|
1427
|
+
_.urlParse = function (url) {
|
1428
|
+
let URLParser = function (url) {
|
1429
|
+
this._fields = {
|
1430
|
+
Username: 4,
|
1431
|
+
Password: 5,
|
1432
|
+
Port: 7,
|
1433
|
+
Protocol: 2,
|
1434
|
+
Host: 6,
|
1435
|
+
Path: 8,
|
1436
|
+
URL: 0,
|
1437
|
+
QueryString: 9,
|
1438
|
+
Fragment: 10,
|
1439
|
+
};
|
1440
|
+
this._values = {};
|
1441
|
+
this._regex =
|
1442
|
+
/^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/;
|
1443
|
+
|
1444
|
+
if (typeof url !== "undefined") {
|
1445
|
+
this._parse(url);
|
1446
|
+
}
|
1447
|
+
};
|
1448
|
+
|
1449
|
+
URLParser.prototype.setUrl = function (url) {
|
1450
|
+
this._parse(url);
|
1451
|
+
};
|
1452
|
+
|
1453
|
+
URLParser.prototype._initValues = function () {
|
1454
|
+
for (let a in this._fields) {
|
1455
|
+
this._values[a] = "";
|
1456
|
+
}
|
1457
|
+
};
|
1458
|
+
|
1459
|
+
URLParser.prototype.addQueryString = function (queryObj) {
|
1460
|
+
if (typeof queryObj !== "object") {
|
1461
|
+
return false;
|
1462
|
+
}
|
1463
|
+
let query = this._values.QueryString || "";
|
1464
|
+
for (let i in queryObj) {
|
1465
|
+
if (new RegExp(i + "[^&]+").test(query)) {
|
1466
|
+
query = query.replace(new RegExp(i + "[^&]+"), i + "=" + queryObj[i]);
|
1467
|
+
} else {
|
1468
|
+
if (query.slice(-1) === "&") {
|
1469
|
+
query = query + i + "=" + queryObj[i];
|
1470
|
+
} else {
|
1471
|
+
if (query === "") {
|
1472
|
+
query = i + "=" + queryObj[i];
|
1473
|
+
} else {
|
1474
|
+
query = query + "&" + i + "=" + queryObj[i];
|
1475
|
+
}
|
1476
|
+
}
|
1477
|
+
}
|
1478
|
+
}
|
1479
|
+
this._values.QueryString = query;
|
1480
|
+
};
|
1481
|
+
|
1482
|
+
URLParser.prototype.getUrl = function () {
|
1483
|
+
let url = "";
|
1484
|
+
url += this._values.Origin;
|
1485
|
+
url += this._values.Port ? ":" + this._values.Port : "";
|
1486
|
+
url += this._values.Path;
|
1487
|
+
url += this._values.QueryString ? "?" + this._values.QueryString : "";
|
1488
|
+
url += this._values.Fragment ? "#" + this._values.Fragment : "";
|
1489
|
+
return url;
|
1490
|
+
};
|
1491
|
+
|
1492
|
+
URLParser.prototype._parse = function (url) {
|
1493
|
+
this._initValues();
|
1494
|
+
|
1495
|
+
let b = this._regex.exec(url);
|
1496
|
+
if (!b) {
|
1497
|
+
Log.i("URLParser::_parse -> Invalid URL");
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
let urlTmp = url.split("#");
|
1501
|
+
let urlPart = urlTmp[0];
|
1502
|
+
let hashPart = urlTmp.slice(1).join("#");
|
1503
|
+
b = this._regex.exec(urlPart);
|
1504
|
+
for (let c in this._fields) {
|
1505
|
+
if (typeof b[this._fields[c]] !== "undefined") {
|
1506
|
+
this._values[c] = b[this._fields[c]];
|
1507
|
+
}
|
1508
|
+
}
|
1509
|
+
this._values["Hostname"] = this._values["Host"].replace(/:\d+$/, "");
|
1510
|
+
this._values["Origin"] =
|
1511
|
+
this._values["Protocol"] + "://" + this._values["Hostname"];
|
1512
|
+
this._values["Fragment"] = hashPart;
|
1513
|
+
};
|
1514
|
+
|
1515
|
+
return new URLParser(url);
|
1516
|
+
};
|
1517
|
+
|
1518
|
+
_.URL = function (url) {
|
1519
|
+
let result = {};
|
1520
|
+
let isURLAPIWorking = function () {
|
1521
|
+
let url;
|
1522
|
+
try {
|
1523
|
+
url = new URL("http://modernizr.com/");
|
1524
|
+
return url.href === "http://modernizr.com/";
|
1525
|
+
} catch (e) {
|
1526
|
+
return false;
|
1527
|
+
}
|
1528
|
+
};
|
1529
|
+
if (typeof window.URL === "function" && isURLAPIWorking()) {
|
1530
|
+
result = new URL(url);
|
1531
|
+
if (!result.searchParams) {
|
1532
|
+
result.searchParams = (function () {
|
1533
|
+
let params = _.getURLSearchParams(result.search);
|
1534
|
+
return {
|
1535
|
+
get: function (searchParam) {
|
1536
|
+
return params[searchParam];
|
1537
|
+
},
|
1538
|
+
};
|
1539
|
+
})();
|
1540
|
+
}
|
1541
|
+
} else {
|
1542
|
+
if (!_.check.isString(url)) {
|
1543
|
+
url = String(url);
|
1544
|
+
}
|
1545
|
+
url = _.trim(url);
|
1546
|
+
let _regex = /^https?:\/\/.+/;
|
1547
|
+
if (_regex.test(url) === false) {
|
1548
|
+
Log.w("Invalid URL");
|
1549
|
+
return;
|
1550
|
+
}
|
1551
|
+
let instance = _.urlParse(url);
|
1552
|
+
result.hash = instance._values.Fragment;
|
1553
|
+
result.host = instance._values.Host
|
1554
|
+
? instance._values.Host +
|
1555
|
+
(instance._values.Port ? ":" + instance._values.Port : "")
|
1556
|
+
: "";
|
1557
|
+
result.href = instance._values.URL;
|
1558
|
+
result.password = instance._values.Password;
|
1559
|
+
result.pathname = instance._values.Path;
|
1560
|
+
result.port = instance._values.Port;
|
1561
|
+
result.search = instance._values.QueryString
|
1562
|
+
? "?" + instance._values.QueryString
|
1563
|
+
: "";
|
1564
|
+
result.username = instance._values.Username;
|
1565
|
+
result.hostname = instance._values.Hostname;
|
1566
|
+
result.protocol = instance._values.Protocol
|
1567
|
+
? instance._values.Protocol + ":"
|
1568
|
+
: "";
|
1569
|
+
result.origin = instance._values.Origin
|
1570
|
+
? instance._values.Origin +
|
1571
|
+
(instance._values.Port ? ":" + instance._values.Port : "")
|
1572
|
+
: "";
|
1573
|
+
result.searchParams = (function () {
|
1574
|
+
let params = _.getURLSearchParams("?" + instance._values.QueryString);
|
1575
|
+
return {
|
1576
|
+
get: function (searchParam) {
|
1577
|
+
return params[searchParam];
|
1578
|
+
},
|
1579
|
+
};
|
1580
|
+
})();
|
1581
|
+
}
|
1582
|
+
return result;
|
1583
|
+
};
|
1584
|
+
|
1585
|
+
// 查询关键字搜索引擎
|
1586
|
+
class SearchKeyword {
|
1587
|
+
static getSourceFromReferrer() {
|
1588
|
+
function getMatchStrFromArr(arr, str) {
|
1589
|
+
for (let i = 0; i < arr.length; i++) {
|
1590
|
+
if (str.split("?")[0].indexOf(arr[i]) !== -1) {
|
1591
|
+
return true;
|
1592
|
+
}
|
1593
|
+
}
|
1594
|
+
}
|
1595
|
+
|
1596
|
+
let utm_reg = "(" + utmTypes.join("|") + ")\\=[^&]+";
|
1597
|
+
let referrer = document.referrer || "";
|
1598
|
+
let url = location.href;
|
1599
|
+
if (url) {
|
1600
|
+
let utm_match = url.match(new RegExp(utm_reg));
|
1601
|
+
if (utm_match && utm_match[0]) {
|
1602
|
+
return "付费广告流量";
|
1603
|
+
} else if (getMatchStrFromArr(searchTypes, referrer)) {
|
1604
|
+
return "自然搜索流量";
|
1605
|
+
} else if (getMatchStrFromArr(socialTypes, referrer)) {
|
1606
|
+
return "社交网站流量";
|
1607
|
+
} else if (referrer === "") {
|
1608
|
+
return "直接流量";
|
1609
|
+
} else {
|
1610
|
+
return "引荐流量";
|
1611
|
+
}
|
1612
|
+
} else {
|
1613
|
+
return "获取url异常";
|
1614
|
+
}
|
1615
|
+
}
|
1616
|
+
|
1617
|
+
static getReferSearchEngine(referrerUrl) {
|
1618
|
+
let hostname = _.getHostname(referrerUrl);
|
1619
|
+
if (!hostname || hostname === "hostname解析异常") {
|
1620
|
+
return "";
|
1621
|
+
}
|
1622
|
+
let searchEngineUrls = {
|
1623
|
+
baidu: [/^.*\.baidu\.com$/],
|
1624
|
+
bing: [/^.*\.bing\.com$/],
|
1625
|
+
google: [
|
1626
|
+
/^www\.google\.com$/,
|
1627
|
+
/^www\.google\.com\.[a-z]{2}$/,
|
1628
|
+
/^www\.google\.[a-z]{2}$/,
|
1629
|
+
],
|
1630
|
+
sm: [/^m\.sm\.cn$/],
|
1631
|
+
so: [/^.+\.so\.com$/],
|
1632
|
+
sogou: [/^.*\.sogou\.com$/],
|
1633
|
+
yahoo: [/^.*\.yahoo\.com$/],
|
1634
|
+
};
|
1635
|
+
|
1636
|
+
let regexes = {};
|
1637
|
+
for (let engine in searchEngineUrls) {
|
1638
|
+
regexes[engine] = searchEngineUrls[engine].map((regex) => {
|
1639
|
+
return new RegExp(regex);
|
1640
|
+
});
|
1641
|
+
}
|
1642
|
+
for (let engine in regexes) {
|
1643
|
+
let regexList = regexes[engine];
|
1644
|
+
for (const regex of regexList) {
|
1645
|
+
if (regex.test(hostname)) {
|
1646
|
+
return engine;
|
1647
|
+
}
|
1648
|
+
}
|
1649
|
+
}
|
1650
|
+
return "未知搜索引擎";
|
1651
|
+
}
|
1652
|
+
|
1653
|
+
static getKeywordFromReferrer(referrerUrl, activeValue) {
|
1654
|
+
referrerUrl = referrerUrl || document.referrer;
|
1655
|
+
if (document && _.check.isString(referrerUrl)) {
|
1656
|
+
if (referrerUrl.indexOf("http") === 0) {
|
1657
|
+
let searchEngine = this.getReferSearchEngine(referrerUrl);
|
1658
|
+
let query = _.getURLSearchParams(referrerUrl);
|
1659
|
+
if (_.check.isEmptyObject(query)) {
|
1660
|
+
return "未取到值";
|
1661
|
+
}
|
1662
|
+
|
1663
|
+
let temp = null;
|
1664
|
+
for (let i in searchKeywords) {
|
1665
|
+
if (searchEngine === i) {
|
1666
|
+
if (_.check.isObject(query)) {
|
1667
|
+
temp = searchKeywords[i];
|
1668
|
+
if (_.check.isArray(temp)) {
|
1669
|
+
for (i = 0; i < temp.length; i++) {
|
1670
|
+
let _value = query[temp[i]];
|
1671
|
+
if (_value) {
|
1672
|
+
if (activeValue) {
|
1673
|
+
return {
|
1674
|
+
active: _value,
|
1675
|
+
};
|
1676
|
+
} else {
|
1677
|
+
return _value;
|
1678
|
+
}
|
1679
|
+
}
|
1680
|
+
}
|
1681
|
+
} else if (query[temp]) {
|
1682
|
+
if (activeValue) {
|
1683
|
+
return {
|
1684
|
+
active: query[temp],
|
1685
|
+
};
|
1686
|
+
} else {
|
1687
|
+
return query[temp];
|
1688
|
+
}
|
1689
|
+
}
|
1690
|
+
}
|
1691
|
+
}
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
return "未取到值";
|
1695
|
+
} else {
|
1696
|
+
if (referrerUrl === "") {
|
1697
|
+
return "未取到值_直接打开";
|
1698
|
+
} else {
|
1699
|
+
return "未取到值_非http的url";
|
1700
|
+
}
|
1701
|
+
}
|
1702
|
+
} else {
|
1703
|
+
return "取值异常_referrer异常_" + String(referrerUrl);
|
1704
|
+
}
|
1705
|
+
}
|
1706
|
+
}
|
1707
|
+
|
1708
|
+
function isVaildFunction(callback) {
|
1709
|
+
if (_.check.isFunction(callback)) {
|
1710
|
+
return true;
|
1711
|
+
} else if (callback && _.check.isObject(callback)) {
|
1712
|
+
return isVaildFunction(callback.callback);
|
1713
|
+
} else {
|
1714
|
+
return false;
|
1715
|
+
}
|
1716
|
+
}
|
1717
|
+
|
1718
|
+
class EventEmitter {
|
1719
|
+
constructor() {
|
1720
|
+
if (!EventEmitter.instance) {
|
1721
|
+
EventEmitter.instance = this;
|
1722
|
+
this.events = {};
|
1723
|
+
}
|
1724
|
+
return EventEmitter.instance;
|
1725
|
+
}
|
1726
|
+
|
1727
|
+
on(e, c) {
|
1728
|
+
if (!e || !c) {
|
1729
|
+
return false;
|
1730
|
+
}
|
1731
|
+
|
1732
|
+
if (!isVaildFunction(c)) {
|
1733
|
+
throw new Error("callback must be a fcuntion");
|
1734
|
+
}
|
1735
|
+
|
1736
|
+
this.events[e] = this.events[e] || [];
|
1737
|
+
if (_.check.isObject(c)) {
|
1738
|
+
this.events[e].push(c);
|
1739
|
+
} else {
|
1740
|
+
this.events[e].push({ callback: c, once: false });
|
1741
|
+
}
|
1742
|
+
|
1743
|
+
return this;
|
1744
|
+
}
|
1745
|
+
|
1746
|
+
prepend(e, c) {
|
1747
|
+
if (!e || !c) {
|
1748
|
+
return false;
|
1749
|
+
}
|
1750
|
+
|
1751
|
+
if (!isVaildFunction(c)) {
|
1752
|
+
throw new Error("callback must be a fcuntion");
|
1753
|
+
}
|
1754
|
+
|
1755
|
+
this.events[e] = this.events[e] || [];
|
1756
|
+
if (_.check.isObject(c)) {
|
1757
|
+
this.events[e].unshift(c);
|
1758
|
+
} else {
|
1759
|
+
this.events[e].unshift({ callback: c, once: false });
|
1760
|
+
}
|
1761
|
+
|
1762
|
+
return this;
|
1763
|
+
}
|
1764
|
+
|
1765
|
+
prependOnce(e, c) {
|
1766
|
+
return this.prepend(e, {
|
1767
|
+
callback: c,
|
1768
|
+
once: true,
|
1769
|
+
});
|
1770
|
+
}
|
1771
|
+
|
1772
|
+
once(e, c) {
|
1773
|
+
return this.on(e, {
|
1774
|
+
callback: c,
|
1775
|
+
once: true,
|
1776
|
+
});
|
1777
|
+
}
|
1778
|
+
|
1779
|
+
off(e, c) {
|
1780
|
+
let cbs = this.events[e];
|
1781
|
+
if (!cbs) return false;
|
1782
|
+
if (_.check.isNumber(c)) {
|
1783
|
+
cbs.splice(c, 1);
|
1784
|
+
} else if (_.check.isFunction(c)) {
|
1785
|
+
for (let i = 0; i < cbs.length; i++) {
|
1786
|
+
if (cbs[i] && cbs[i].callback === c) {
|
1787
|
+
cbs.splice(i, 1);
|
1788
|
+
}
|
1789
|
+
}
|
1790
|
+
}
|
1791
|
+
return this;
|
1792
|
+
}
|
1793
|
+
|
1794
|
+
emit(e, args) {
|
1795
|
+
let cbs = this.events[e];
|
1796
|
+
if (!cbs) {
|
1797
|
+
return false;
|
1798
|
+
}
|
1799
|
+
|
1800
|
+
for (let cb of cbs) {
|
1801
|
+
if (_.check.isObject(cb)) {
|
1802
|
+
cb.callback.call(this, args || {});
|
1803
|
+
if (cb.once) {
|
1804
|
+
this.off(e, cb.callback);
|
1805
|
+
}
|
1806
|
+
}
|
1807
|
+
}
|
1808
|
+
|
1809
|
+
return this;
|
1810
|
+
}
|
1811
|
+
|
1812
|
+
clear(e) {
|
1813
|
+
if (e && this.events(e)) {
|
1814
|
+
this.events[e] = [];
|
1815
|
+
} else {
|
1816
|
+
this.events = {};
|
1817
|
+
}
|
1818
|
+
}
|
1819
|
+
|
1820
|
+
getEvent(e) {
|
1821
|
+
if (e && this.events[e]) {
|
1822
|
+
return this.events[e];
|
1823
|
+
} else {
|
1824
|
+
return this.events;
|
1825
|
+
}
|
1826
|
+
}
|
1827
|
+
}
|
1828
|
+
|
1829
|
+
_.mitt = new EventEmitter();
|
1830
|
+
|
1831
|
+
_.initUrlChange = function () {
|
1832
|
+
let currentUrl = location.href;
|
1833
|
+
let historyPushState = history.pushState;
|
1834
|
+
let historyReplaceState = history.replaceState;
|
1835
|
+
|
1836
|
+
if (_.check.isFunction(historyPushState)) {
|
1837
|
+
history.pushState = function () {
|
1838
|
+
historyPushState.apply(history, arguments);
|
1839
|
+
_.mitt.emit("urlChange", currentUrl);
|
1840
|
+
currentUrl = location.href;
|
1841
|
+
};
|
1842
|
+
}
|
1843
|
+
|
1844
|
+
if (_.check.isFunction(historyReplaceState)) {
|
1845
|
+
history.replaceState = function () {
|
1846
|
+
historyReplaceState.apply(history, arguments);
|
1847
|
+
_.mitt.emit("urlChange", currentUrl);
|
1848
|
+
currentUrl = location.href;
|
1849
|
+
};
|
1850
|
+
}
|
1851
|
+
|
1852
|
+
let pageEventMode = historyPushState ? "popstate" : "hashchange";
|
1853
|
+
|
1854
|
+
_.addEvent(window, pageEventMode, function () {
|
1855
|
+
_.mitt.emit("urlChange", currentUrl);
|
1856
|
+
currentUrl = location.href;
|
1857
|
+
});
|
1858
|
+
};
|
1859
|
+
|
1860
|
+
// (function(){
|
1861
|
+
// let hasCircularReference = function(obj, seen = new Set()) {
|
1862
|
+
// if (typeof obj !== 'object' || obj === null) {
|
1863
|
+
// return false;
|
1864
|
+
// }
|
1865
|
+
|
1866
|
+
// if (seen.has(obj)) {
|
1867
|
+
// return true;
|
1868
|
+
// }
|
1869
|
+
|
1870
|
+
// seen.add(obj);
|
1871
|
+
|
1872
|
+
// for (let key in obj) {
|
1873
|
+
// if (hasCircularReference(obj[key], seen)) {
|
1874
|
+
// return true;
|
1875
|
+
// }
|
1876
|
+
// }
|
1877
|
+
|
1878
|
+
// seen.delete(obj);
|
1879
|
+
|
1880
|
+
// return false;
|
1881
|
+
// }
|
1882
|
+
|
1883
|
+
// let JSONStringfy = JSON.stringify;
|
1884
|
+
// let newJSONStringfy = function(obj, ...option){
|
1885
|
+
// if(!hasCircularReference(obj)){
|
1886
|
+
// return JSONStringfy(obj, ...option);
|
1887
|
+
// }
|
1888
|
+
// throw new Error("There is a circular reference, please check the data type. If you are using the Vue3 framework, please check if you are using JSON.stringfy to convert ref types.");
|
1889
|
+
// }
|
1890
|
+
// JSON.stringify = newJSONStringfy;
|
1891
|
+
// })();
|
1892
|
+
|
1893
|
+
|
1894
|
+
export { _, Log, SDKDebug, SearchKeyword };
|