-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
290 lines (286 loc) · 7.62 KB
/
index.html
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, width=320" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>Stack Timer</title>
<style>
html,body { margin:0; padding:0; }
body { font-family:Georgia; background:url('wood_pattern.png') repeat; }
.panel {margin:5px; border:1px dotted #999; text-align:center;}
@font-face {font-family:'digital'; src:url('DS-DIGI.TTF');}
.digit-font {font-size:32px; font-family:digital, arial, verdana; text-shadow:0 0 5px rgba(255, 255, 255, 1); }
#timeTime {display:inline-block; min-width:160px; text-align:left; }
h3 {margin:2px 0; font-size:32px; font-weight:700; color:#f33;}
button {width:95%; font-family:Georgia; font-size:32px;}
#popBtn {color:#33f;}
#pushBtn {color:#f33;}
input {width:90%; height:40px; font-size:20px; text-align:center;}
#stackView {text-align:left;}
.large-font {font-size:larger;}
.spent {background:#000; color:#fff;}
h4 {margin:2px 0 0 0; font-size:24px;}
ul {margin:4px 0; padding-left:32px; padding-right:16px; text-align:left;}
#headOfListForHistory {display:none;}
.not-important {font-style:italic; color:#777;}
#scrollTopBtn {position:fixed; right:5px; bottom:5px; font-weight:700; font-size:36px; color:#080; cursor:pointer;}
</style>
</head>
<body>
<div id="timerPanel" class="panel">
<span id="timeDay" class="digit-font">0</span>days
<span id="timeTime" class="digit-font">
<span id="timeHour">00</span>:<span id="timeMin">00</span>:<span id="timeSec">00</span>.<span id="timeMsec">00</span>
</span>
</div>
<div id="popPanel" class="panel">
<h3 id="popText"></h3>
<button id="popBtn">end</button>
</div>
<div id="pushPanel" class="panel">
<input type="text" id="pushText" placeholder="title"/><br/>
<button id="pushBtn">start</button>
</div>
<div id="stackPanel" class="panel">
<h4>stack</h4>
<ul id="stackView"></ul>
</div>
<div id="logPanel" class="panel">
<h4>history</h4>
<ul>
<li id="headOfListForHistory"></li>
</ul>
</div>
<address>Stack Timer 1.0 by azki( @ azki.org).</address>
<a id="scrollTopBtn" href="#">↑</a>
<!-- 귀찮아.. 최근 100개만 있으면 댔지.. 머.
<div id="morePanel" class="panel">
<button id="moreBtn">more..</button>
</div>
-->
<script src="jquery.js"></script>
<script>
var DATA_VER = '1.0.1';
var MAX_LOG = 100;
var data = [];
var log = [];
var time = 0;
function saveData() {
localStorage.setItem('ppt_data_ver', DATA_VER);
localStorage.setItem('ppt_time', '' + time);
localStorage.setItem('ppt_data', JSON.stringify(data));
localStorage.setItem('ppt_log', JSON.stringify(log));
}
function loadData() {
var dataVer = localStorage.getItem('ppt_data_ver');
if (dataVer === DATA_VER) {
time = localStorage.getItem('ppt_time');
data = JSON.parse(localStorage.getItem('ppt_data'));
log = JSON.parse(localStorage.getItem('ppt_log'));
} else {
if (DATA_VER) {
//TODO.azki 데이타 바꿔주기.
}
time = +new Date();
data = [{
title: 'idle',
elapse: -1
}];
log = [];
}
}
function drawLog() {
var i, len;
len = log.length;
for (i = 0; i < len; i += 1) {
addLog(log[i]);
}
}
function getTopItem() {
return data[data.length - 1];
}
function calculationTime() {
var item = getTopItem();
if (0 <= item.elapse) {
time = +new Date() - item.elapse;
}
item.elapse = -1;
}
function drawTitle() {
var item = getTopItem();
$('#popText').text(item.title);
}
function createItem() {
return {
title: $('#pushText').val(),
elapse: 0
};
}
function formatTime(selector, unit, elapse) {
var value = elapse % unit;
$(selector).text(9 < value ? value : '0' + value);
elapse -= value;
return elapse / unit;
}
function drawTime() {
var elapse = +new Date() - time;
elapse = Math.floor(elapse / 10);
elapse = formatTime('#timeMsec', 100, elapse);
elapse = formatTime('#timeSec', 60, elapse);
elapse = formatTime('#timeMin', 60, elapse);
elapse = formatTime('#timeHour', 24, elapse);
$('#timeDay').text(elapse);
}
function loopTimer() {
setTimeout(function () {
drawTime();
loopTimer();
}, Math.floor(Math.random() * 100));
}
function getElapseString(elapse) {
var value, unit, timeArr = [], result = '';
if (elapse < 0) {
return 'ing';
}
elapse = Math.ceil(elapse / 1000);
unit = 60;
value = elapse % unit;
timeArr.push(9 < value ? value : '0' + value);
elapse -= value;
elapse /= unit;
unit = 60;
value = elapse % unit;
timeArr.push(9 < value ? value : '0' + value);
elapse -= value;
elapse /= unit;
unit = 24;
value = elapse % unit;
timeArr.push(9 < value ? value : '0' + value);
elapse -= value;
elapse /= unit;
if (0 < elapse) {
result += elapse + 'd ';
}
elapse = timeArr.pop();
if (0 < elapse) {
result += elapse + 'h ';
}
elapse = timeArr.pop();
if (0 < elapse) {
result += elapse + 'm ';
}
elapse = timeArr.pop();
result += elapse + 's';
return result;
}
var colorOfType = {
'start': '#f33',
'end': '#33f'
};
function addLog(logItem) {
var $div, $li = $('<li>');
$('<span>').css({
color: colorOfType[logItem.type]
}).text(logItem.item.title).appendTo($li);
$('<span>').addClass('not-important').text(' (' + logItem.timeStamp + ')').appendTo($li);
if (logItem.elapse) {
$div = $('<div>').addClass('spent').appendTo($li);
$('<span>').addClass('large-font').text(getElapseString(logItem.elapse)).appendTo($div);
$('<span>').addClass('not-important').text(' spent for ').appendTo($div);
$('<span>').addClass('large-font').text(logItem.item.title).appendTo($div);
}
$('#headOfListForHistory').after($li);
}
function getTimeStamp() {
return (new Date()).toString().split(' GMT')[0];
}
function calculationElapse() {
var elapse = +new Date() - time;
getTopItem().elapse = elapse;
}
function pushTimer(item) {
data.push(item);
var logItem = {
type: 'start',
item: item,
timeStamp: getTimeStamp()
};
log.push(logItem);
if (MAX_LOG < log.length) {
log.shift();
}
addLog(logItem);
}
function popTimer() {
if (data.length < 2) {
return;
}
var logItem = {
type: 'end',
item: data.pop(),
timeStamp: getTimeStamp(),
elapse: +new Date() - time
};
log.push(logItem);
if (MAX_LOG < log.length) {
log.shift();
}
addLog(logItem);
}
$('#pushText').keydown(function (ev) {
if (ev.keyCode === 13) {
ev.preventDefault();
$('#pushBtn').click();
}
});
function resetTextAndScrollTop() {
$('#pushText').val('');
scrollTo(0, 0);
}
function drawStackView() {
var i, $parent, $item;
$parent = $('#stackView');
$parent.empty();
for (i = data.length - 2; 0 <= i; i -= 1) {
$item = $('<li>');
$('<span>').addClass('large-font').text(data[i].title).appendTo($item);
$('<span>').addClass('not-important').text(' has ').appendTo($item);
$('<span>').addClass('large-font').text(getElapseString(data[i].elapse)).appendTo($item);
$parent.append($item);
}
}
$('#pushBtn').click(function () {
if ($('#pushText').val() === '') {
$('#pushText').focus();
return;
}
var item = createItem();
calculationElapse();
pushTimer(item);
calculationTime();
saveData();
drawTitle();
drawStackView();
resetTextAndScrollTop();
});
$('#popBtn').click(function () {
popTimer();
calculationTime();
saveData();
drawTitle();
drawStackView();
resetTextAndScrollTop();
});
$(function () {
loadData();
drawTitle();
drawStackView();
drawLog();
loopTimer();
saveData();
});
</script>
</body>
</html>