-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
113 lines (110 loc) · 3.38 KB
/
test.html
File metadata and controls
113 lines (110 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.parent {
width: 200px;
height: 200px;
background-color: blue;
}
.child {
width: 50px;
height: 50px;
background-color: red;
margin: auto;
}
</style>
</head>
<body>
<div id="useragent"></div>
<div class="parent">
<div class="child">child</div>
</div>
<script>
// Array.prototype.shuffle = function () {
// let j;
// let i = this.length;
// while (i > 0) {
// j = parseInt(Math.random() * i);
// i--;
// [this[j], this[i]] = [this[i], this[j]];
// }
// return this;
// };
// // 带权重的数组乱序,格式[{value:"val1", priority:1},{value:"val2", priority:9},...]
// // priority的值在[0,1]之间,包括0,小于1
// Array.prototype.shuffleWithPriority = function () {
// let prioritySum = this.reduce(
// (total, elem) => total + elem.priority,
// 0
// );
// let j;
// let i = this.length;
// while (i > 0) {
// let rnd = Math.random()
// j = parseInt(rnd * i);
// i--;
// console.log((this[i].priority/prioritySum), rnd);
// if((this[i].priority/prioritySum)>rnd && !this[j].switch){
// [this[j], this[i]] = [this[i], this[j]];
// this[j].switch = true;
// }
// }
// return this;
// };
// Array.prototype.random = function () {
// const len = this.length;
// return this[parseInt(Math.random() * len)];
// };
// // let arr = [1, 2, 3, 4, 5, 6, 7];
// // console.log(arr.shuffle());
// // console.log(arr.shuffle());
// // console.log(arr.random());
// console.log(
// [
// { value: 1, priority: 1 },
// { value: 2, priority: 10 },
// { value: 3, priority: 20 },
// { value: 4, priority: 30 },
// { value: 5, priority: 50 },
// { value: 6, priority: 60 },
// ].shuffleWithPriority()
// );
// const ua = navigator.userAgent
// is chrome
// const isChrome = /(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i.test(ua)
// is safari
// const isSafari = /(iPhone|iPod|iPad).*AppleWebKit(?=.*Safari)/.test(ua)
// const isMobile = /[^-]mobi/i.test(ua)
// document.querySelector("#useragent").innerText = isChrome + ',' + isSafari + "," + ua+","+isMobile;
function testPromise(type) {
if (type === 1) {
return Promise.resolve("sucess");
}
return Promise.reject("error");
}
function wrapPro(type) {
return testPromise(type).catch((err) => {
console.log("err is " + err);
});
}
wrapPro(1)
.then((result) => {
console.log("wrapPro success", "result is " + result);
})
.catch((err) => {
console.log("wrapPro catch err: " + err);
});
wrapPro(0)
.then((result) => {
console.log("wrapPro success", "result is " + result);
})
.catch((err) => {
console.log("wrapPro catch err: " + err);
});
</script>
</body>
</html>