-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.html
214 lines (192 loc) · 5.78 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<textarea style="width: 300px; height: 300px;">select json_agg(t)
from (
SELECT routine_name
FROM information_schema.routines
WHERE routine_type = 'FUNCTION'
AND routine_schema = 'public'
order by routine_name
) t;</textarea>
<script>
function getLine() {
let start = textarea.selectionStart;
const strings = textarea.value;
if (strings[start] === '\n' && start - 1 > 0) {
start--;
}
while (start > 0 && strings[start] != '\n') {
start--;
}
let end = textarea.selectionEnd;
while (end - 1 < strings.length && strings[end] != '\n') {
end++;
}
return [strings.substring(start, end), start, end]
}
const textarea = document.querySelector('textarea');
document.addEventListener('keydown', evt => {
if (evt.key === 'F1') {
const p = getLine();
console.log(p);
evt.preventDefault();
}
})
/*
let start = textarea.selectionStart;
let end = textarea.selectionEnd;
while (start > 0) {
if (/\s/.test(textarea.value[start])) {
let j = 0;
while (start > 0 && /\s/.test(textarea.value[start])) {
if (textarea.value[start] === '\n') {
j++;
}
start--;
}
if (j > 2) {
break;
}
}
start--;
}
start++;
while (end < textarea.value.length) {
if (/\s/.test(textarea.value[end])) {
let j = 0;
while (end < textarea.value.length > 0 && /\s/.test(textarea.value[end])) {
if (textarea.value[end] === '\n') {
j++;
}
end++;
}
if (j > 2) {
break;
}
}
end++;
}
console.log(start,end, textarea.value.substring(start,end))
*/
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
</script>
<script>
(() => {
function getDatePart() {
const d = new Date();
const seconds = d.getTime() / 1000 | 0;
hoursInSeconds = (seconds - d.getTimezoneOffset() * 60) % (3600 * 24);
console.log(seconds - hoursInSeconds);
}
getDatePart();
})()
</script>
</body>
</html>
<div
style="width: 24px;height: 24px;fill: currentColor;color: #333;display:flex;align-items: center;justify-content: center;margin-right: 16px;">
</div>
<!-- <script>
[...new Array(10).keys()].map(x => 1672588800 + 3600 * 24 + 3600 * 24 * 7 * (x + 1));
</script> -->
<script>
function shortDateString(seconds) {
const date = new Date(seconds * 1000);
return `${date.getMonth() + 1}月${date.getDate()}日`;
}
function formatSeconds(s) {
if (isNaN(s)) return '0:00';
if (s < 0) s = -s;
const time = {
hour: Math.floor(s / 3600) % 24,
minute: Math.floor(s / 60) % 60,
};
return Object.entries(time)
.filter((val, index) => index || val[1])
.map(val => (val[1] + '').padStart(2, '0'))
.join(':');
}
function durationToSeconds(duration) {
let result = 0;
if (/(\d{1,2}:){1,2}\d{1,2}/.test(duration)) {
const pieces = duration.split(':');
for (let i = pieces.length - 1; i > -1; i--) {
result += Math.pow(60, i) * parseInt(pieces[pieces.length - i - 1]);
}
return result;
}
result = parseInt(duration);
if (isNaN(result)) {
result = 0;
}
return result;
}
function timeSpan(atime, btime) {
var milliseconds = +(btime || new Date()) - +atime;
var seconds = ~~(milliseconds / 1000);
var minutes = ~~(milliseconds / (1 * 60 * 1000));
var hours = ~~(milliseconds / (1 * 60 * 60 * 1000));
var days = ~~(milliseconds / (1 * 24 * 60 * 60 * 1000));
var years = ~~(days / 365.5);
return {
years,
days,
hours,
minutes,
seconds,
milliseconds
};
}
function timeAgo(time, locales = 'zh') {
const ts = timeSpan(time);
if (!i18n[locales]) locales = 'zh';
if (ts.seconds < 60) return i18n[locales].justNow;
if (ts.minutes < 60) return ts.minutes + ' ' + i18n[locales].minutesAgo;
if (ts.hours < 24) return ts.hours + ' ' + i18n[locales].hoursAgo;
if (ts.days < 7) return ts.days + ' ' + i18n[locales].daysAgo;
if (ts.days < 30) return ~~(ts.days / 7) + ' ' + i18n[locales].weeksAgo;
if (ts.years < 1) return ~~(ts.days / 30) + ' ' + i18n[locales].monthsAgo;
return ts.years + ' ' + i18n[locales].yearsAgo;
}
const i18n = {
zh: {
justNow: '刚刚',
minutesAgo: '分钟前',
hoursAgo: '小时前',
daysAgo: '天前',
weeksAgo: '周前',
monthsAgo: '个月前',
yearsAgo: '年前',
},
en: {
justNow: 'just now',
minutesAgo: 'minutes ago',
hoursAgo: 'hours ago',
daysAgo: 'days ago',
weeksAgo: 'weeks ago',
monthsAgo: 'months ago',
yearsAgo: 'years ago',
},
};
</script>
<script>
console.log(`swtich(){
${[{"id":2,"name":"月卡"},
{"id":3,"name":"年卡"},
{"id":4,"name":"次卡"},
{"id":1,"name":"周卡"}].map(x=>{
return `case ${x.id}:{
return '${x.name}'
}`
}).join('\n')}
default:
return ''
}`)
</script>