-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
143 lines (120 loc) · 2.91 KB
/
index.js
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* @author monkindey
*/
'use strict';
!(function() {
var aboutMe = document.getElementById('about-me');
// var color = ['#0e96a2', '#67a61c', '#fff', '#fff', '#fff'];
var color = ['#fff', '#fff', '#fff'];
var charactor = '';
function getCharColor(charactor) {
var index = parseInt(Math.random() * color.length) - 1;
return '<span style="color:' + color[index] + '">' + charactor + '</span>';
}
// 简单的promise
var Promise = function() {
this.thens = [];
};
Promise.prototype.then = function(next) {
this.thens.push(next);
return this;
};
Promise.prototype.resolve = function() {
var next = this.thens.shift();
if (next) {
var defer = next.call(null, arguments);
defer instanceof Promise && (defer.thens = this.thens);
}
};
// 函数科里化
var step = function(opts) {
opts = opts || {};
var cmd = opts.cmd || '';
var cwd = opts.cwd || '';
var cb = opts.cb;
var chars = cmd.split('');
if (cwd) {
chars.unshift(cwd);
}
return function() {
var defer = new Promise();
var containEl = document.createElement(opts.containEl || 'p');
containEl.className = opts.cls || 'line';
aboutMe.appendChild(containEl);
// requestAnimationFrame
setTimeout(function type() {
if (chars.length !== 0) {
charactor = chars.shift();
// aboutMe.innerHTML += getCharColor(charactor);
containEl.innerHTML += charactor;
setTimeout(type, 100);
} else {
cb && cb();
defer.resolve();
}
}, 100);
return defer;
};
};
var step1 = step({
cwd: '/Users/monkindey>',
cmd: ' whois',
cls: ''
});
var step2 = step({
cmd:
'I am a Web Developer, graduated from Guangdong University of Technology.',
cls: 'result line'
});
var step3 = step({
cmd: 'My name is KihoCham, I live in HangZhou now.',
cls: 'result line'
});
var step4 = step({
cwd: '/Users/monkindey>',
cmd: ' cd hobby'
});
var step5 = step({
cwd: '/Users/monkindey/hobby> ',
cmd: ' dir'
});
var step6 = step({
cmd: 'basketball coding',
cls: 'result line'
});
var step7 = step({
cwd: '/Users/monkindey/hobby> ',
cmd: 'cd coding'
});
var step8 = step({
cwd: '/Users/monkindey/hobby/coding> ',
cmd: 'dir'
});
var step9 = step({
cmd: 'github',
cls: 'result line'
});
var step10 = step({
cwd: '/Users/monkindey/hobby/coding> ',
cmd: 'net start github'
});
var step11 = step({
cmd: 'opening......',
cb: function() {
if (confirm('Will you take a look at my github ?')) {
window.location.href = 'https://github.com/monkindey';
}
}
});
step1()
.then(step2)
.then(step3)
.then(step4)
.then(step5)
.then(step6)
.then(step7)
.then(step8)
.then(step9)
.then(step10)
.then(step11);
})();