-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.html
315 lines (297 loc) · 11.6 KB
/
map.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<html>
<head>
<title>新建文本文档 (114514).txt</title>
<style>
table {
border-collapse: collapse;
margin-bottom: 10px;
}
#table_main {
background-image: linear-gradient(to bottom right, #A9C9FF, #FFBBEC 25%, #A9C9FF 50%, #FFBBEC 75%, #A9C9FF);
/* -webkit-text-fill-color: transparent; */
-webkit-background-clip: content-box;
-webkit-background-size: 200% 100%;
-webkit-animation: maskedAnimation_0 2s infinite linear;
}
#table_main td, #table_iseedeadpeople td {
color: #000000;
text-align: center;
border: 1px solid black;
height: 80px;
width: 80px;
}
#table_main td:hover {
outline-color: #fedcba;
outline-style: solid;
outline-width: 4px;
outline-offset: -4px;
}
.open {
background-color: #FFFFFF;
}
.completed {
background-color: #AAAAAA;
}
@keyframes maskedAnimation_0 {
0% {
background-position: -200% 0;
}
100% {
background-position: 0 -200%;
}
}
#table_header td {
width: 300px;
}
.div_button {
background-color: #F0F0F07F;
padding: 10px;
border-radius: 3px;
border-color: #000;
border-style: solid;
border-width: 1px;
text-align: center;
}
textarea {
width: 100%;
resize: none;
}
</style>
</head>
<body>
<table id="table_header">
<tr>
<td>
<div class="div_button" id="div_settings" onclick="handle_button_settings();">设置</div>
</td>
</tr>
</table>
<table id="table_settings" style="display: none;">
<tr>
<td>
<hr>
<div class="div_button" id="div_iseedeadpeople" onclick="handle_button_iseedeadpeople();">透视!</div>
<br>
</td>
</tr>
<tr>
<td>
<input type="number" id="input_row" min="1" max="10" value="5">行 × <input type="number" id="input_col" min="1" max="10" value="5">列
</td>
</tr>
<tr>
<td>
每行对应一个格子,从上到下从左到右,空行表示空的格子
</td>
</tr>
<tr>
<td>
不足的行会自动在最后补充空行,多余的行会被自动忽略
</td>
</tr>
<tr>
<td>
修改后格子内容总是会自动更新
</td>
</tr>
<tr>
<td>
点击保存设置后,行数或列数变化时会重新生成所有格子
</td>
</tr>
<tr>
<td>
<br>
<textarea id="textarea_contents" rows="10" onchange="update_contents();draw_table();"></textarea>
<hr>
</td>
</tr>
</table>
<table id="table_iseedeadpeople" style="display: none;">
</table>
<table id="table_main">
</table>
<script>
let total_row = 5, total_col = 5;
let contents = [];
let td_list_open = [], td_list_completed = [];
let iseedeadpeople_enabled = false;
let temp_table_main = '';
function handle_button_settings() {
document.getElementById('table_main').style.display = '';
document.getElementById('table_iseedeadpeople').style.display = 'none';
document.getElementById('div_iseedeadpeople').innerHTML = '透视!';
if (document.getElementById('table_settings').style.display == 'none') {
document.getElementById('table_settings').style.display = '';
document.getElementById('div_settings').innerHTML = '保存设置';
}
else {
document.getElementById('table_settings').style.display = 'none';
document.getElementById('div_settings').innerHTML = '设置';
save_data();
draw_table();
}
}
function handle_button_iseedeadpeople() {
if (document.getElementById('table_iseedeadpeople').style.display == 'none') {
document.getElementById('table_main').style.display = 'none';
document.getElementById('table_iseedeadpeople').style.display = '';
document.getElementById('div_iseedeadpeople').innerHTML = '关闭透视';
}
else {
document.getElementById('table_main').style.display = '';
document.getElementById('table_iseedeadpeople').style.display = 'none';
document.getElementById('div_iseedeadpeople').innerHTML = '透视!';
}
}
function update_contents() {
contents = document.getElementById('textarea_contents').value.split('\n');
}
function swap_content(current_row, current_col) {
let td = `td_${current_row}_${current_col}`;
let td_index = (current_row - 1) * total_col + current_col - 1;
if (document.getElementById(td).classList.contains('completed')) {
document.getElementById(td).innerHTML = '';
}
else {
document.getElementById(td).innerHTML = contents[td_index];
}
}
function func_td(current_row, current_col) {
let td = `td_${current_row}_${current_col}`;
let td_index = (current_row - 1) * total_col + current_col - 1;
if (document.getElementById(td).classList.contains('open')) {
document.getElementById(td).classList.remove('open');
document.getElementById(td).classList.add('completed');
td_list_open.splice(td_list_open.indexOf(td_index), 1);
td_list_completed.push(td_index);
}
else if (document.getElementById(td).classList.contains('completed')) {
swap_content(current_row, current_col);
document.getElementById(td).classList.remove('completed');
td_list_completed.splice(td_list_completed.indexOf(td_index), 1);
}
else {
swap_content(current_row, current_col);
document.getElementById(td).classList.add('open');
td_list_open.push(td_index);
}
save_data();
}
function draw_table() {
let total_row_old = total_row, total_col_old = total_col;
total_row = document.getElementById('input_row').value;
total_col = document.getElementById('input_col').value;
if (!total_row || total_row < 1 || total_row > 10) {
total_row = 5;
}
if (!total_col || total_col < 1 || total_col > 10) {
total_col = 5;
}
if (total_row_old != total_row || total_col_old != total_col ) {
td_list_open = [];
td_list_completed = [];
}
document.getElementById('input_row').value = total_row;
document.getElementById('input_col').value = total_col;
let new_table_main = '';
let new_table_iseedeadpeople = `<tr>`;
while (contents.length < total_row * total_col) {
contents.push('');
}
for (let i = 1; i <= total_row; i++) {
new_table_main += `<tr>`;
new_table_iseedeadpeople += `<tr>`;
for (let j = 1; j <= total_col; j++) {
td_index = (i - 1) * total_col + j - 1;
td_class = '';
td_content = '';
if (td_list_open.indexOf(td_index) != -1) {
td_class = 'open';
td_content = contents[td_index];
}
if (td_list_completed.indexOf(td_index) != -1) {
td_class = 'completed';
td_content = contents[td_index];
}
new_table_main += `<td class="${td_class}" id="td_${i}_${j}" onclick="func_td(${i}, ${j})">${td_content}</td>`;
new_table_iseedeadpeople += `<td class="open">${contents[td_index]}</td>`;
}
new_table_main += `</tr>`;
new_table_iseedeadpeople += `</tr>`;
}
document.getElementById('table_main').innerHTML = new_table_main;
document.getElementById('table_iseedeadpeople').innerHTML = new_table_iseedeadpeople;
}
function save_data() {
if (!window.localStorage) {
console.error("浏览器不支持localStorage");
}
else {
console.log("save_data()");
let wish, cost, storage = window.localStorage;
let total_row_old = total_row, total_col_old = total_col;
total_row = document.getElementById('input_row').value;
total_col = document.getElementById('input_col').value;
if (!total_row || total_row < 1 || total_row > 10) {
total_row = 5;
}
if (!total_col || total_col < 1 || total_col > 10) {
total_col = 5;
}
if (total_row_old != total_row || total_col_old != total_col ) {
td_list_open = [];
td_list_completed = [];
}
update_contents();
while (contents.length < total_row * total_col) {
contents.push('');
}
let data_to_save = {
'contents': contents,
'td_list_open': td_list_open,
'td_list_completed': td_list_completed,
'total_row': total_row,
'total_col': total_col,
};
storage['data_ji_map'] = JSON.stringify(data_to_save);
return true;
}
}
function load_data() {
if (!window.localStorage) {
console.error("浏览器不支持localStorage");
}
else {
console.log("load_data()");
let storage = window.localStorage;
if (storage['data_ji_map']) {
const data = JSON.parse(storage['data_ji_map']);
total_row = data['total_row'];
total_col = data['total_row'];
contents = data['contents'];
td_list_open = data['td_list_open'];
td_list_completed = data['td_list_completed'];
}
else {
// 初始化
total_row = 5;
total_col = 5;
contents = [];
while (contents.length < total_row * total_col) {
contents.push('');
}
td_list_open = [];
td_list_completed = [];
}
document.getElementById('input_row').value = total_row;
document.getElementById('input_col').value = total_col;
document.getElementById('textarea_contents').value = contents.join('\n');
}
}
// 页面加载完成时执行
load_data();
draw_table();
</script>
</body>
</html>