-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
500 lines (361 loc) · 14.4 KB
/
main.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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
// query
function initialRequest() {
if(localStorage.getItem('is_loadeed')){
console.log("你已经是个成熟的插件了!");
}
else{
//var arra=[1,2,3,4];
var d_link = [];
var title = [];
var d_mark = [];
var d_time = [];
var pencil = [];
var pencil_list = ['<mark style="background-color:#00FF90">$1</mark>'];
var remark = [];
localStorage.setItem('title' ,JSON.stringify(title));
localStorage.setItem('d_link',JSON.stringify(d_link));
localStorage.setItem('d_mark',JSON.stringify(d_mark));
localStorage.setItem('d_time',JSON.stringify(d_time));
localStorage.setItem('pencil',JSON.stringify(pencil));
localStorage.setItem('pencil_list',JSON.stringify(pencil_list));
localStorage.setItem('remark',JSON.stringify(remark));
localStorage.setItem('is_auto',1);
localStorage.setItem('is_auto_remark',1);
localStorage.setItem('active_pencil',pencil_list[0]);
localStorage.setItem('is_loadeed',true);
}
}
// render
function showResult() {
if(localStorage.getItem('is_auto')>0)
{
document.getElementById('label_auto').innerHTML="自动标记已打开";
document.getElementById('autoBtn').value="关闭自动标记";
}
else{
document.getElementById('label_auto').innerHTML="自动标记已关闭";
document.getElementById('autoBtn').value="打开自动标记";
}
if(localStorage.getItem('is_auto_remark')>0)
{
document.getElementById('label_auto_remark').innerHTML="备注显示已打开";
document.getElementById('auto_remark').value="关闭备注显示";
}
else{
document.getElementById('label_auto_remark').innerHTML="备注显示已关闭";
document.getElementById('auto_remark').value="打开备注显示";
}
var table = '<table width="600"><thead><tr><th width="250">链接</th><th width="150">标记</th><th width="150">备注</th><th width="100">时间</th><th width="100">操作</th></tr></thead><tbody>';
var title_read=JSON.parse(localStorage.getItem('title'));
var d_link_read=JSON.parse(localStorage.getItem('d_link'));
var d_mark_read=JSON.parse(localStorage.getItem('d_mark'));
var d_time_read=JSON.parse(localStorage.getItem('d_time'));
var pencil_read=JSON.parse(localStorage.getItem('pencil'));
var pencil_list=JSON.parse(localStorage.getItem('pencil_list'));
var remark_read=JSON.parse(localStorage.getItem('remark'));
var selectID = document.getElementById("selectID");
selectID.innerHTML = '';
for (var i in pencil_list) {
var option = document.createElement("option");// 创建option元素
option.appendChild(document.createTextNode(pencil_list[i]));
option.setAttribute("value", pencil_list[i]);
option.id=pencil_list[i];
selectID.appendChild(option);
}
selectID.value=localStorage.getItem('active_pencil');
//arr.forEach(function (item, index, array) {
d_link_read.forEach(function(item, index, array){
table += '<tr>';
table += '<td><a href=\"' + d_link_read[index] + '\">' + title_read[index] + '</a></td>';
table += '<td>' + d_mark_read[index] + '</td>';
table += '<td>' + remark_read[index] + '</td>';
table += '<td>' + d_time_read[index] + '</td>';
table += '<td>' + '<input type="button" id=\"del'+index+'\" value="删除" />' + '</td>';
table += '</tr>';
})
table += '</tbody></table>';
console.log(table) ;
document.getElementById('link_data').innerHTML = table;
var btnObjs = new Array(d_link_read.length);
d_link_read.forEach(function(item, index, array){
btnObjs[index]=document.getElementById("del"+index);
btnObjs[index].onclick = function () {
title_read.splice(index,1);
d_link_read.splice(index,1);
d_mark_read.splice(index,1);
d_time_read.splice(index,1);
pencil_read.splice(index,1);
remark_read.splice(index,1);
localStorage.setItem('title',JSON.stringify(title_read));
localStorage.setItem('d_link',JSON.stringify(d_link_read));
localStorage.setItem('d_mark',JSON.stringify(d_mark_read));
localStorage.setItem('d_time',JSON.stringify(d_time_read));
localStorage.setItem('pencil',JSON.stringify(pencil_read));
localStorage.setItem('remark',JSON.stringify(remark_read));
showResult();
};
})
}
document.getElementById('changePen').onclick = function() {
var selectID = document.getElementById("selectID");
localStorage.setItem('active_pencil',selectID.value);
alert("画笔已更改为:"+selectID.value)
}
// add Pencil
document.getElementById('addPencil').onclick = function() {
var con_top = document.getElementById('con_top' );
var link_data = document.getElementById('link_data' );
var o_button = document.getElementById('o_button' );
var addBtn = document.getElementById('addBtn' );
var listBtn = document.getElementById('listBtn' );
var autoBtn = document.getElementById('autoBtn' );
var label_auto = document.getElementById('label_auto');
var changePen = document.getElementById('changePen' );
var selectID = document.getElementById('selectID' );
var addPencil = document.getElementById('addPencil' );
var delPencil = document.getElementById('delPencil' );
con_top .removeChild(link_data );
o_button.removeChild(addBtn );
o_button.removeChild(listBtn );
o_button.removeChild(autoBtn );
o_button.removeChild(label_auto );
o_button.removeChild(changePen );
o_button.removeChild(selectID );
o_button.removeChild(addPencil );
o_button.removeChild(delPencil );
var name_link = document.createElement("p");
name_link.innerHTML = "画笔:";
var input_link = document.createElement('input');
input_link.type = 'text';
input_link.id = 'new_pencil';
var saveBtn = document.createElement('input');
saveBtn.type = 'button';
saveBtn.id = 'saveBtn';
saveBtn.value = 'save';
o_button.appendChild(name_link);
o_button.appendChild(input_link);
o_button.appendChild(saveBtn);
var error_label = document.createElement("p");
error_label.innerHTML = "";
o_button.appendChild(error_label);
document.getElementById('saveBtn').onclick = function() {
var new_pencil_value = document.getElementById('new_pencil').value;
if(!new_pencil_value)
{
//var error_label = document.createElement("p");
error_label.innerHTML = "错误!";
//o_button.appendChild(error_label);
}
else{
var pencil_list=JSON.parse(localStorage.getItem('pencil_list'));
pencil_list.push(new_pencil_value);
localStorage.setItem('pencil_list',JSON.stringify(pencil_list));
o_button.removeChild(name_link);
o_button.removeChild(input_link);
o_button.removeChild(saveBtn);
o_button.appendChild(addBtn );
o_button.appendChild(listBtn );
o_button.appendChild(addPencil );
o_button.appendChild(delPencil );
o_button.appendChild(autoBtn );
o_button.appendChild(label_auto );
o_button.appendChild(selectID );
o_button.appendChild(changePen );
con_top .appendChild(link_data );
showResult();
}
}
}
function del_pencil_func(con_top) {
var table = '<table width="600"><thead><tr><th width="250">画笔</th><th width="150">操作</th></tr></thead><tbody>';
var pencil_list=JSON.parse(localStorage.getItem('pencil_list'));
pencil_list.forEach(function(item, index, array){
table += '<tr>';
table += '<td><xmp>' + pencil_list[index] + '</xmp></td>';
table += '<td>' + '<input type="button" id=\"delpencil'+index+'\" value="删除" />' + '</td>';
table += '</tr>';
})
table += '</tbody></table>';
document.getElementById('pencil_list').innerHTML = table;
var btnObjs = new Array(pencil_list.length);
pencil_list.forEach(function(item, index, array){
btnObjs[index]=document.getElementById("delpencil"+index);
btnObjs[index].onclick = function () {
pencil_list.splice(index,1);
localStorage.setItem('pencil_list',JSON.stringify(pencil_list));
del_pencil_func();
}})
}
// add Pencil
document.getElementById('delPencil').onclick = function() {
var con_top = document.getElementById('con_top' );
var link_data = document.getElementById('link_data' );
var o_button = document.getElementById('o_button' );
var addBtn = document.getElementById('addBtn' );
var listBtn = document.getElementById('listBtn' );
var autoBtn = document.getElementById('autoBtn' );
var label_auto = document.getElementById('label_auto');
var changePen = document.getElementById('changePen' );
var selectID = document.getElementById('selectID' );
var addPencil = document.getElementById('addPencil' );
var delPencil = document.getElementById('delPencil' );
con_top .removeChild(link_data );
o_button.removeChild(addBtn );
o_button.removeChild(listBtn );
o_button.removeChild(autoBtn );
o_button.removeChild(label_auto );
o_button.removeChild(changePen );
o_button.removeChild(selectID );
o_button.removeChild(addPencil );
o_button.removeChild(delPencil );
var input_link = document.createElement('div');
input_link.id = 'pencil_list';
con_top.appendChild(input_link);
del_pencil_func(con_top);
};
// add
document.getElementById('addBtn').onclick = function() {
var con_top = document.getElementById('con_top' );
var link_data = document.getElementById('link_data' );
var o_button = document.getElementById('o_button' );
var addBtn = document.getElementById('addBtn' );
var listBtn = document.getElementById('listBtn' );
var autoBtn = document.getElementById('autoBtn' );
var label_auto = document.getElementById('label_auto');
var changePen = document.getElementById('changePen' );
var selectID = document.getElementById('selectID' );
var addPencil = document.getElementById('addPencil' );
var delPencil = document.getElementById('delPencil' );
con_top .removeChild(link_data );
o_button.removeChild(addBtn );
o_button.removeChild(listBtn );
o_button.removeChild(autoBtn );
o_button.removeChild(label_auto );
o_button.removeChild(changePen );
o_button.removeChild(selectID );
o_button.removeChild(addPencil );
o_button.removeChild(delPencil );
var name_link = document.createElement("p");
name_link.innerHTML = "链接:";
var name_mark = document.createElement("p");
name_mark.innerHTML = "标记:";
var name_rema = document.createElement("p");
name_rema.innerHTML = "备注:";
var input_link = document.createElement('input');
input_link.type = 'text';
input_link.id = 'new_link';
var input_mark = document.createElement('input');
input_mark.type = 'text';
input_mark.id = 'new_mark';
var input_rema = document.createElement('input');
input_rema.type = 'text';
input_rema.id = 'new_rema';
var saveBtn = document.createElement('input');
saveBtn.type = 'button';
saveBtn.id = 'saveBtn';
saveBtn.value = 'save';
o_button.appendChild(name_link);
o_button.appendChild(input_link);
o_button.appendChild(name_mark);
o_button.appendChild(input_mark);
o_button.appendChild(name_rema);
o_button.appendChild(input_rema);
o_button.appendChild(saveBtn);
var error_label = document.createElement("p");
error_label.innerHTML = "";
o_button.appendChild(error_label);
document.getElementById('saveBtn').onclick = function() {
var new_link_value = document.getElementById('new_link').value;
var new_mark_value = document.getElementById('new_mark').value;
var new_rema_value = document.getElementById('new_rema').value;
if(!new_link_value || !new_mark_value)
{
//var error_label = document.createElement("p");
error_label.innerHTML = "错误!";
//o_button.appendChild(error_label);
}
else{
error_label.innerHTML = "";
var dd = new Date();
var y = dd.getFullYear();
var m = dd.getMonth() + 1;
var d = dd.getDate();
if(dd.getHours()<10)
{var h = "0"+dd.getHours();}
else
{var h = dd.getHours();}
if(dd.getMinutes()<10)
{var mi = "0"+dd.getMinutes();}
else
{var mi = dd.getMinutes();}
var new_time_value = y + "年" + m + "月" + d + "日" + h+":"+mi ;
var title_read=JSON.parse(localStorage.getItem('title'));
var d_link_read=JSON.parse(localStorage.getItem('d_link'));
var d_mark_read=JSON.parse(localStorage.getItem('d_mark'));
var d_time_read=JSON.parse(localStorage.getItem('d_time'));
var pencil_read=JSON.parse(localStorage.getItem('pencil'));
var remark_read=JSON.parse(localStorage.getItem('remark'));
title_read.push(new_link_value);
d_link_read.push(new_link_value);
d_mark_read.push(new_mark_value);
d_time_read.push(new_time_value);
pencil_read.push("");
remark_read.push(new_rema_value);
localStorage.setItem('title',JSON.stringify(title_read));
localStorage.setItem('d_link',JSON.stringify(d_link_read));
localStorage.setItem('d_mark',JSON.stringify(d_mark_read));
localStorage.setItem('d_time',JSON.stringify(d_time_read));
localStorage.setItem('pencil',JSON.stringify(pencil_read));
localStorage.setItem('remark',JSON.stringify(remark_read));
//showResult();
o_button.removeChild(name_link);
o_button.removeChild(new_link);
o_button.removeChild(name_mark);
o_button.removeChild(new_mark);
o_button.removeChild(name_rema);
o_button.removeChild(input_rema);
o_button.removeChild(saveBtn);
o_button.appendChild(addBtn );
o_button.appendChild(listBtn );
o_button.appendChild(addPencil );
o_button.appendChild(delPencil );
o_button.appendChild(autoBtn );
o_button.appendChild(label_auto );
o_button.appendChild(selectID );
o_button.appendChild(changePen );
con_top .appendChild(link_data );
showResult();
}
}
}
document.getElementById('listBtn').onclick = function() {
showResult();
}
document.getElementById('autoBtn').onclick = function() {
if(localStorage.getItem('is_auto')>0)
{
localStorage.setItem('is_auto',0);
document.getElementById('label_auto').innerHTML="自动标记已关闭";
document.getElementById('autoBtn').value="打开自动标记";
}
else{
localStorage.setItem('is_auto',1);
document.getElementById('label_auto').innerHTML="自动标记已打开";
document.getElementById('autoBtn').value="关闭自动标记";
}
}
document.getElementById('auto_remark').onclick = function() {
if(localStorage.getItem('is_auto_remark')>0)
{
localStorage.setItem('is_auto_remark',0);
document.getElementById('label_auto_remark').innerHTML="备注显示已关闭";
document.getElementById('auto_remark').value="打开备注显示";
}
else{
localStorage.setItem('is_auto_remark',1);
document.getElementById('label_auto_remark').innerHTML="备注显示已打开";
document.getElementById('auto_remark').value="关闭备注显示";
}
}
initialRequest();
showResult();