visual-buried-point-platform-h5 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +8 -0
- package/README.md +434 -0
- package/dist/buried-point-h5.js +1 -0
- package/image/101.png +0 -0
- package/image/102.png +0 -0
- package/image/103.png +0 -0
- package/image/104.png +0 -0
- package/image/105.png +0 -0
- package/image/img1.png +0 -0
- package/image/img2.png +0 -0
- package/image/img3.png +0 -0
- package/lsi-md5.js +22 -0
- package/package.json +37 -0
- package/rollup.config.js +36 -0
- package/src/config/global.ts +82 -0
- package/src/config/index.ts +138 -0
- package/src/hack.ts +201 -0
- package/src/handlers.ts +882 -0
- package/src/index.ts +341 -0
- package/src/reporter.ts +122 -0
- package/src/typing.d.ts +24 -0
- package/src/typings/index.d.ts +300 -0
- package/src/utils/cache.ts +30 -0
- package/src/utils/cacheCu.ts +30 -0
- package/src/utils/cachePuv.ts +30 -0
- package/src/utils/cloneDocument.ts +236 -0
- package/src/utils/db.ts +172 -0
- package/src/utils/getXPath.ts +166 -0
- package/src/utils/index.ts +69 -0
- package/src/utils/lazyReport.ts +425 -0
- package/src/utils/tools.ts +574 -0
- package/src/utils/xhr.ts +4 -0
- package/tsconfig.json +35 -0
package/image/101.png
ADDED
|
Binary file
|
package/image/102.png
ADDED
|
Binary file
|
package/image/103.png
ADDED
|
Binary file
|
package/image/104.png
ADDED
|
Binary file
|
package/image/105.png
ADDED
|
Binary file
|
package/image/img1.png
ADDED
|
Binary file
|
package/image/img2.png
ADDED
|
Binary file
|
package/image/img3.png
ADDED
|
Binary file
|
package/lsi-md5.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const MD5 = require("md5");
|
|
3
|
+
|
|
4
|
+
const packageJson = require("./package.json");
|
|
5
|
+
const { name, version } = packageJson;
|
|
6
|
+
// MD5
|
|
7
|
+
const combinedString = name + version;
|
|
8
|
+
const md5Str = MD5(combinedString);
|
|
9
|
+
packageJson.lsi = md5Str;
|
|
10
|
+
//base64
|
|
11
|
+
// const combinedString = name.substring(0, 16) + "v" + version;
|
|
12
|
+
// const base64Str = btoa(combinedString);
|
|
13
|
+
// packageJson.lsi = base64Str;
|
|
14
|
+
|
|
15
|
+
const updatedPackageJson = JSON.stringify(packageJson, null, 2);
|
|
16
|
+
fs.writeFileSync("./package.json", updatedPackageJson, "utf8");
|
|
17
|
+
|
|
18
|
+
console.log('write package.json "lsi" value success ');
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
md5Str,
|
|
22
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "visual-buried-point-platform-h5",
|
|
3
|
+
"version": "1.3.4",
|
|
4
|
+
"lsi": "9c772ffbee84e8f3e1a5df28ef6a3fa3",
|
|
5
|
+
"description": "可视化埋点WebSdk",
|
|
6
|
+
"main": "dist/buried-point-h5.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "rollup -c -w",
|
|
9
|
+
"build": "rollup -c --environment INCLUDE_DEPS,BUILD:production && node lsi-md5.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": ""
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"html2canvas": "^1.4.1",
|
|
19
|
+
"js-base64": "^3.7.3",
|
|
20
|
+
"md5": "^2.3.0",
|
|
21
|
+
"pako": "1.0.11",
|
|
22
|
+
"tslib": "^1.9.3",
|
|
23
|
+
"typescript": "^3.5.3"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@babel/core": "^7.5.5",
|
|
27
|
+
"babel-preset-es2015": "^6.24.1",
|
|
28
|
+
"rollup": "^1.20.2",
|
|
29
|
+
"rollup-plugin-babel": "^4.3.3",
|
|
30
|
+
"rollup-plugin-commonjs": "^10.0.2",
|
|
31
|
+
"rollup-plugin-node-resolve": "^5.2.0",
|
|
32
|
+
"rollup-plugin-replace": "^2.2.0",
|
|
33
|
+
"rollup-plugin-typescript": "^1.0.1",
|
|
34
|
+
"rollup-plugin-uglify": "^6.0.2",
|
|
35
|
+
"webpack": "^4.39.2"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import babel from "rollup-plugin-babel";
|
|
2
|
+
import commonjs from "rollup-plugin-commonjs";
|
|
3
|
+
import resolve from "rollup-plugin-node-resolve";
|
|
4
|
+
import replace from "rollup-plugin-replace";
|
|
5
|
+
import typescript from "rollup-plugin-typescript";
|
|
6
|
+
import { uglify } from "rollup-plugin-uglify";
|
|
7
|
+
let pkg = require("./package.json");
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
input: "src/index.ts",
|
|
12
|
+
output: {
|
|
13
|
+
file: "dist/buried-point-h5.js",
|
|
14
|
+
format: "umd",
|
|
15
|
+
name: "BuriedPointH5",
|
|
16
|
+
sourcemap: false, // 是否打包sourcemap
|
|
17
|
+
},
|
|
18
|
+
plugins: [
|
|
19
|
+
replace({
|
|
20
|
+
VERSION: pkg.version,
|
|
21
|
+
LSI: pkg.lsi,
|
|
22
|
+
delimiters: ["{{", "}}"],
|
|
23
|
+
}),
|
|
24
|
+
typescript(),
|
|
25
|
+
commonjs({ extensions: [".js", ".ts"] }),
|
|
26
|
+
resolve({
|
|
27
|
+
jsnext: true,
|
|
28
|
+
main: true,
|
|
29
|
+
browser: true,
|
|
30
|
+
}),
|
|
31
|
+
babel({
|
|
32
|
+
exclude: "node_modules/**",
|
|
33
|
+
}),
|
|
34
|
+
process.env.BUILD === "production" ? uglify() : null,
|
|
35
|
+
],
|
|
36
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { randomString } from "../utils/tools";
|
|
2
|
+
|
|
3
|
+
// 默认参数
|
|
4
|
+
export let GlobalVal = {
|
|
5
|
+
page: "", // 当前页面
|
|
6
|
+
sid: "", // session id,页面切换就会改变
|
|
7
|
+
sBegin: Date.now(), // 修改sid时间
|
|
8
|
+
_health: {
|
|
9
|
+
errcount: 0,
|
|
10
|
+
apisucc: 0,
|
|
11
|
+
apifail: 0,
|
|
12
|
+
},
|
|
13
|
+
// 在iframe方式下 是否开启埋点
|
|
14
|
+
circle: false,
|
|
15
|
+
// 在iframe方式下 是否开启回显
|
|
16
|
+
cssInserted: false,
|
|
17
|
+
/** 在打通与APP之间的通信时 是否开启埋点操作 默认关闭 */
|
|
18
|
+
enableJavaScriptBridgeCircle: false,
|
|
19
|
+
/** 用户Id */
|
|
20
|
+
userId: "",
|
|
21
|
+
/** 匿名Id */
|
|
22
|
+
anonId: "",
|
|
23
|
+
/** 全局访问来源途径 */
|
|
24
|
+
accessPath: "",
|
|
25
|
+
/** 进入网站的渠道页面来源 */
|
|
26
|
+
referrer: "",
|
|
27
|
+
/** 入口页面的Url */
|
|
28
|
+
enterUrl: "",
|
|
29
|
+
/** 离开页面的Url */
|
|
30
|
+
leaveUrl: "",
|
|
31
|
+
/** 链路id */
|
|
32
|
+
trackId: "",
|
|
33
|
+
/** 操作系统 */
|
|
34
|
+
os: "",
|
|
35
|
+
/** 新数据结构操作系统 */
|
|
36
|
+
osNew: "",
|
|
37
|
+
/** 系统版本 */
|
|
38
|
+
osVersion: "",
|
|
39
|
+
/** 新数据结构设备类型 */
|
|
40
|
+
deviceType: 2,
|
|
41
|
+
/** 浏览器名字 */
|
|
42
|
+
browserName: "",
|
|
43
|
+
/** 浏览器版本 */
|
|
44
|
+
browserVersion: "",
|
|
45
|
+
/** lsi */
|
|
46
|
+
lsi: "",
|
|
47
|
+
/** packageName */
|
|
48
|
+
packageName: "",
|
|
49
|
+
/** 型号 */
|
|
50
|
+
brand: "",
|
|
51
|
+
/** app信息 */
|
|
52
|
+
app: null,
|
|
53
|
+
/** 设备信息 */
|
|
54
|
+
device: null,
|
|
55
|
+
/** 访问页面路由记录数组 */
|
|
56
|
+
routerArray: [],
|
|
57
|
+
/** 应用载体 */
|
|
58
|
+
ecology: "",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export function setGlobalPage(page) {
|
|
62
|
+
GlobalVal.page = page;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function setGlobalSid() {
|
|
66
|
+
GlobalVal.sid = randomString();
|
|
67
|
+
GlobalVal.sBegin = Date.now();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function setGlobalHealth(type: string, success?: boolean) {
|
|
71
|
+
if (type === "error") GlobalVal._health.errcount++;
|
|
72
|
+
if (type === "api" && success) GlobalVal._health.apisucc++;
|
|
73
|
+
if (type === "api" && !success) GlobalVal._health.apifail++;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function resetGlobalHealth() {
|
|
77
|
+
GlobalVal._health = {
|
|
78
|
+
errcount: 0,
|
|
79
|
+
apisucc: 0,
|
|
80
|
+
apifail: 0,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { IInitConfig } from "../typings";
|
|
2
|
+
|
|
3
|
+
// 默认参数
|
|
4
|
+
export let Config: IInitConfig = {
|
|
5
|
+
// 上报地址
|
|
6
|
+
reportUrl: "",
|
|
7
|
+
/** 新的数据结构自定义上报 */
|
|
8
|
+
reportEventUrl: "",
|
|
9
|
+
/** 获取已埋点事件列表 */
|
|
10
|
+
eventListPath: "",
|
|
11
|
+
/** puv上报地址 */
|
|
12
|
+
reportPUVUrl: "",
|
|
13
|
+
/** 获取元数据配置表*/
|
|
14
|
+
metaConfigPath: "",
|
|
15
|
+
// 提交参数
|
|
16
|
+
token: "",
|
|
17
|
+
/** 业务板块 */
|
|
18
|
+
busSegment: "",
|
|
19
|
+
/** 业务模块 */
|
|
20
|
+
module: "",
|
|
21
|
+
// app版本
|
|
22
|
+
appVersion: "1.0.0",
|
|
23
|
+
// 环境 默认开发环境 `dev`
|
|
24
|
+
environment: "dev",
|
|
25
|
+
// 脚本延迟上报时间
|
|
26
|
+
outtime: 300,
|
|
27
|
+
// 开启单页面?
|
|
28
|
+
enableSPA: true,
|
|
29
|
+
// 是否自动上报pv
|
|
30
|
+
autoSendPv: true,
|
|
31
|
+
// 是否上报页面性能数据
|
|
32
|
+
isPage: false,
|
|
33
|
+
// 是否上报ajax性能数据
|
|
34
|
+
isAjax: false,
|
|
35
|
+
// 是否上报页面资源数据
|
|
36
|
+
isResource: false,
|
|
37
|
+
// 是否上报错误信息
|
|
38
|
+
isError: false,
|
|
39
|
+
// 是否录屏
|
|
40
|
+
isRecord: false,
|
|
41
|
+
// 是否上报行为
|
|
42
|
+
isBehavior: true,
|
|
43
|
+
// 是否开启页面浏览时长采集
|
|
44
|
+
enableTrackPageLeave: true,
|
|
45
|
+
/** 是否开启了CSS HASH值 默认开启*/
|
|
46
|
+
isOpenCSSHash: true,
|
|
47
|
+
ignore: {
|
|
48
|
+
ignoreErrors: [],
|
|
49
|
+
ignoreUrls: [],
|
|
50
|
+
ignoreApis: [],
|
|
51
|
+
},
|
|
52
|
+
behavior: {
|
|
53
|
+
console: [], // 取值可以是"debug", "info", "warn", "log", "error"
|
|
54
|
+
click: true,
|
|
55
|
+
},
|
|
56
|
+
// 最长上报数据长度
|
|
57
|
+
maxLength: 1000,
|
|
58
|
+
// Web JS SDK 的 H5 页面,在嵌入到 App 后,H5 内的事件可以通过 App 进行发送 默认关闭
|
|
59
|
+
enableJavaScriptBridge: false,
|
|
60
|
+
// 打通H5与APP通信后,上报数据ID
|
|
61
|
+
androidToken: null,
|
|
62
|
+
iosToken: null,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// 根据环境 设置上报地址
|
|
66
|
+
function setReportPath(environment: string): {
|
|
67
|
+
reportUrl: string;
|
|
68
|
+
reportEventUrl: string;
|
|
69
|
+
reportTrackUrl: string;
|
|
70
|
+
eventListPath: string;
|
|
71
|
+
reportPUVUrl: string;
|
|
72
|
+
metaConfigPath: string;
|
|
73
|
+
} {
|
|
74
|
+
switch (environment) {
|
|
75
|
+
case "test":
|
|
76
|
+
return {
|
|
77
|
+
reportUrl:
|
|
78
|
+
"https://buryingpoint.gcongo.com.cn/api/report/data/reportDataFromWeb",
|
|
79
|
+
reportEventUrl: "https://buryingpoint.gcongo.com.cn/client/api/event",
|
|
80
|
+
reportTrackUrl: "https://buryingpoint.gcongo.com.cn/client/api/track",
|
|
81
|
+
eventListPath: "https://buryingpoint.gcongo.com.cn/api/event/query/",
|
|
82
|
+
reportPUVUrl:
|
|
83
|
+
"https://buryingpoint.gcongo.com.cn/api/report/data/reportData/browse",
|
|
84
|
+
metaConfigPath:
|
|
85
|
+
"https://buryingpoint.gcongo.com.cn/api/metadataConfig/queryByProject/",
|
|
86
|
+
};
|
|
87
|
+
case "press":
|
|
88
|
+
return {
|
|
89
|
+
reportUrl:
|
|
90
|
+
"https://buryingpoint.gcongo.com.cn/api/report/data/reportDataFromWeb",
|
|
91
|
+
reportEventUrl: "",
|
|
92
|
+
reportTrackUrl: "",
|
|
93
|
+
eventListPath: "https://buryingpoint.gcongo.com.cn/api/event/query/",
|
|
94
|
+
reportPUVUrl:
|
|
95
|
+
"https://buryingpoint.gcongo.com.cn/api/report/data/reportData/browse",
|
|
96
|
+
metaConfigPath:
|
|
97
|
+
"https://buryingpoint.gcongo.com.cn/api/metadataConfig/queryByProject/",
|
|
98
|
+
};
|
|
99
|
+
case "prod":
|
|
100
|
+
return {
|
|
101
|
+
reportUrl:
|
|
102
|
+
"https://buryingpoint.onebuygz.com/api/report/data/reportDataFromWeb",
|
|
103
|
+
reportEventUrl: "https://buryingpoint.onebuygz.com/client/api/event",
|
|
104
|
+
reportTrackUrl: "https://buryingpoint.onebuygz.com/client/api/track",
|
|
105
|
+
eventListPath: "https://buryingpoint.onebuygz.com/api/event/query/",
|
|
106
|
+
reportPUVUrl:
|
|
107
|
+
"https://buryingpoint.onebuygz.com/api/report/data/reportData/browse",
|
|
108
|
+
metaConfigPath:
|
|
109
|
+
"https://buryingpoint.onebuygz.com/api/metadataConfig/queryByProject/",
|
|
110
|
+
};
|
|
111
|
+
default:
|
|
112
|
+
return {
|
|
113
|
+
reportUrl:
|
|
114
|
+
"https://buryingpoint.onebuygz.com/api/report/data/reportDataFromWeb",
|
|
115
|
+
reportEventUrl: "https://buryingpoint.onebuygz.com/client/api/event",
|
|
116
|
+
reportTrackUrl: "https://buryingpoint.onebuygz.com/client/api/track",
|
|
117
|
+
eventListPath: "https://buryingpoint.onebuygz.com/api/event/query/",
|
|
118
|
+
reportPUVUrl:
|
|
119
|
+
"https://buryingpoint.onebuygz.com/api/report/data/reportData/browse",
|
|
120
|
+
metaConfigPath:
|
|
121
|
+
"https://buryingpoint.onebuygz.com/api/metadataConfig/queryByProject/",
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 设置参数
|
|
127
|
+
export function setConfig(options: IInitConfig) {
|
|
128
|
+
const pathData = setReportPath(options.environment);
|
|
129
|
+
Config = {
|
|
130
|
+
...Config,
|
|
131
|
+
...options,
|
|
132
|
+
...pathData,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function getConfig(e: string): string {
|
|
137
|
+
return e ? (Config[e] ? Config[e] : {}) : {};
|
|
138
|
+
}
|
package/src/hack.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseUrl,
|
|
3
|
+
fnToString,
|
|
4
|
+
warn,
|
|
5
|
+
dispatchCustomEvent,
|
|
6
|
+
parseHash,
|
|
7
|
+
getLocationHref,
|
|
8
|
+
} from "./utils/tools";
|
|
9
|
+
import { handleBehavior, handleApi, setPage } from "./handlers";
|
|
10
|
+
import { Config } from "./config";
|
|
11
|
+
/**
|
|
12
|
+
* @监听console
|
|
13
|
+
* hack console
|
|
14
|
+
* "debug", "info", "warn", "log", "error"
|
|
15
|
+
*/
|
|
16
|
+
export function hackConsole() {
|
|
17
|
+
if (window && window.console) {
|
|
18
|
+
for (var e = Config.behavior.console, n = 0; e.length; n++) {
|
|
19
|
+
var r = e[n];
|
|
20
|
+
var action = window.console[r];
|
|
21
|
+
if (!window.console[r]) return;
|
|
22
|
+
(function (r, action) {
|
|
23
|
+
window.console[r] = function () {
|
|
24
|
+
var i = Array.prototype.slice.apply(arguments);
|
|
25
|
+
var s: consoleBehavior = {
|
|
26
|
+
type: "console",
|
|
27
|
+
data: {
|
|
28
|
+
level: r,
|
|
29
|
+
message: JSON.stringify(i),
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
handleBehavior(s);
|
|
33
|
+
action && action.apply(null, i);
|
|
34
|
+
};
|
|
35
|
+
})(r, action);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* hack pushstate replaceState
|
|
42
|
+
* 派送historystatechange historystatechange事件
|
|
43
|
+
* @export
|
|
44
|
+
* @param {('pushState' | 'replaceState')} e
|
|
45
|
+
*/
|
|
46
|
+
export function hackState(e: "pushState" | "replaceState") {
|
|
47
|
+
let t = history[e];
|
|
48
|
+
"function" == typeof t &&
|
|
49
|
+
((history[e] = function (n, i, s) {
|
|
50
|
+
!window["__bb_onpopstate_"] && hackOnpopstate(); // 调用pushState或replaceState时hack Onpopstate
|
|
51
|
+
let len = arguments.length ?? 0;
|
|
52
|
+
let c = 1 === len ? [arguments[0]] : Array.apply(null, arguments),
|
|
53
|
+
u = getLocationHref(),
|
|
54
|
+
f = t.apply(history, c);
|
|
55
|
+
if (!s || "string" != typeof s) return f;
|
|
56
|
+
if (s === u) return f;
|
|
57
|
+
try {
|
|
58
|
+
let l = u.split("#"),
|
|
59
|
+
h = s.split("#"),
|
|
60
|
+
p = parseUrl(l[0]),
|
|
61
|
+
d = parseUrl(h[0]),
|
|
62
|
+
g = l[1] && l[1].replace(/^\/?(.*)/, "$1"),
|
|
63
|
+
v = h[1] && h[1].replace(/^\/?(.*)/, "$1");
|
|
64
|
+
p !== d
|
|
65
|
+
? dispatchCustomEvent("historystatechanged", d)
|
|
66
|
+
: g !== v && dispatchCustomEvent("historystatechanged", v);
|
|
67
|
+
} catch (m) {
|
|
68
|
+
warn("[retcode] error in " + e + ": " + m);
|
|
69
|
+
}
|
|
70
|
+
return f;
|
|
71
|
+
}),
|
|
72
|
+
(history[e].toString = fnToString(e)));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function hackhook() {
|
|
76
|
+
hackFetch();
|
|
77
|
+
hackAjax();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function hackFetch() {
|
|
81
|
+
if ("function" == typeof window.fetch) {
|
|
82
|
+
var __oFetch_ = window.fetch;
|
|
83
|
+
window["__oFetch_"] = __oFetch_;
|
|
84
|
+
window.fetch = function (t, o) {
|
|
85
|
+
var a =
|
|
86
|
+
1 === arguments.length ? [arguments[0]] : Array.apply(null, arguments);
|
|
87
|
+
var timestamp = Date.now(),
|
|
88
|
+
url = (t && "string" != typeof t ? (t as any).url : t) || "",
|
|
89
|
+
page = parseUrl(url as string);
|
|
90
|
+
if (!page) return __oFetch_.apply(window, a);
|
|
91
|
+
return __oFetch_.apply(window, a).then(function (e) {
|
|
92
|
+
var response = e.clone(),
|
|
93
|
+
headers = response.headers;
|
|
94
|
+
if (headers && "function" === typeof headers.get) {
|
|
95
|
+
var network = headers.get("content-type");
|
|
96
|
+
if (network && !/(text)|(json)/.test(network)) return e;
|
|
97
|
+
}
|
|
98
|
+
var time = Date.now() - timestamp;
|
|
99
|
+
response.text().then(function (res) {
|
|
100
|
+
if (response.ok) {
|
|
101
|
+
handleApi(
|
|
102
|
+
page,
|
|
103
|
+
!0,
|
|
104
|
+
time,
|
|
105
|
+
status,
|
|
106
|
+
res.substr(0, 1000) || "",
|
|
107
|
+
timestamp
|
|
108
|
+
);
|
|
109
|
+
} else {
|
|
110
|
+
handleApi(
|
|
111
|
+
page,
|
|
112
|
+
!1,
|
|
113
|
+
time,
|
|
114
|
+
status,
|
|
115
|
+
res.substr(0, 1000) || "",
|
|
116
|
+
timestamp
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return e;
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 如果返回过长,会被截断,最长1000个字符
|
|
127
|
+
function hackAjax() {
|
|
128
|
+
if ("function" == typeof window.XMLHttpRequest) {
|
|
129
|
+
var timestamp = 0,
|
|
130
|
+
url = "",
|
|
131
|
+
page = "";
|
|
132
|
+
var __oXMLHttpRequest_ = window.XMLHttpRequest;
|
|
133
|
+
window["__oXMLHttpRequest_"] = __oXMLHttpRequest_;
|
|
134
|
+
window.XMLHttpRequest = function (t) {
|
|
135
|
+
var xhr = new __oXMLHttpRequest_(t);
|
|
136
|
+
if (!xhr.addEventListener) return xhr;
|
|
137
|
+
var open = xhr.open,
|
|
138
|
+
send = xhr.send;
|
|
139
|
+
xhr.open = function (method: string, url?: string) {
|
|
140
|
+
var a =
|
|
141
|
+
1 === arguments.length
|
|
142
|
+
? [arguments[0]]
|
|
143
|
+
: Array.apply(null, arguments);
|
|
144
|
+
url = url;
|
|
145
|
+
page = parseUrl(url);
|
|
146
|
+
|
|
147
|
+
open.apply(xhr, a);
|
|
148
|
+
};
|
|
149
|
+
xhr.send = function () {
|
|
150
|
+
timestamp = Date.now();
|
|
151
|
+
var a =
|
|
152
|
+
1 === arguments.length
|
|
153
|
+
? [arguments[0]]
|
|
154
|
+
: Array.apply(null, arguments);
|
|
155
|
+
send.apply(xhr, a);
|
|
156
|
+
};
|
|
157
|
+
xhr.onreadystatechange = function () {
|
|
158
|
+
if (page && 4 === xhr.readyState) {
|
|
159
|
+
var time = Date.now() - timestamp;
|
|
160
|
+
if (xhr.status >= 200 && xhr.status <= 299) {
|
|
161
|
+
var status = xhr.status || 200;
|
|
162
|
+
if ("function" == typeof xhr.getResponseHeader) {
|
|
163
|
+
var r = xhr.getResponseHeader("Content-Type");
|
|
164
|
+
if (r && !/(text)|(json)/.test(r)) return;
|
|
165
|
+
}
|
|
166
|
+
handleApi(
|
|
167
|
+
page,
|
|
168
|
+
!0,
|
|
169
|
+
time,
|
|
170
|
+
status,
|
|
171
|
+
xhr.responseText.substr(0, Config.maxLength) || "",
|
|
172
|
+
timestamp
|
|
173
|
+
);
|
|
174
|
+
} else {
|
|
175
|
+
handleApi(
|
|
176
|
+
page,
|
|
177
|
+
!1,
|
|
178
|
+
time,
|
|
179
|
+
status || "FAILED",
|
|
180
|
+
xhr.responseText.substr(0, Config.maxLength) || "",
|
|
181
|
+
timestamp
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return xhr;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function hackOnpopstate() {
|
|
192
|
+
window["__bb_onpopstate_"] = window.onpopstate;
|
|
193
|
+
window.onpopstate = function () {
|
|
194
|
+
let len = arguments.length ?? 0;
|
|
195
|
+
for (let r = len, a = new Array(r), o = 0; o < r; o++) a[o] = arguments[o];
|
|
196
|
+
let page = Config.enableSPA
|
|
197
|
+
? parseHash(location.hash.toLowerCase())
|
|
198
|
+
: location.pathname.toLowerCase();
|
|
199
|
+
setPage(page, false);
|
|
200
|
+
};
|
|
201
|
+
}
|