File size: 34,097 Bytes
5af3022
 
 
 
0087982
 
 
 
 
09c8e31
0087982
12286b2
0087982
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12286b2
0087982
12286b2
 
 
 
0087982
 
 
 
12286b2
 
 
 
 
 
0087982
 
 
12286b2
0087982
12286b2
 
0087982
 
 
 
12286b2
 
 
 
 
0087982
 
 
 
12286b2
 
0087982
 
 
 
 
 
 
12286b2
 
0087982
 
 
12286b2
 
 
 
 
 
 
 
 
 
0087982
 
6fa3b2e
 
 
 
 
 
 
 
 
0087982
 
12286b2
 
0087982
 
 
 
12286b2
 
 
0087982
 
 
12286b2
 
 
0087982
 
 
 
12286b2
0087982
 
 
12286b2
 
0087982
 
 
12286b2
 
0087982
 
 
 
12286b2
 
0087982
 
 
12286b2
0087982
12286b2
 
 
 
 
 
0087982
 
 
 
12286b2
 
0087982
 
 
 
12286b2
0087982
 
 
12286b2
0087982
12286b2
 
0087982
 
 
12286b2
 
 
0087982
 
 
12286b2
0087982
 
 
 
12286b2
0087982
 
 
 
12286b2
 
 
 
0087982
 
 
 
12286b2
 
0087982
 
 
 
 
 
 
12286b2
 
 
 
 
 
 
0087982
 
12286b2
 
0087982
 
12286b2
 
0087982
 
12286b2
 
 
 
 
 
 
 
 
 
0087982
09c8e31
 
5af3022
 
09c8e31
fb3e427
 
 
6fa3b2e
fb3e427
09c8e31
5af3022
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd1febc
5af3022
 
 
 
 
 
 
 
 
fb3e427
 
 
5af3022
 
 
 
 
 
 
 
 
 
 
 
cd1febc
 
fb3e427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af1c1d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb3e427
af1c1d6
 
09c8e31
fb3e427
 
 
 
f687325
 
 
 
 
 
 
 
 
 
 
 
 
 
fb3e427
 
 
 
 
 
 
 
 
 
6fa3b2e
 
fb3e427
 
 
 
 
 
 
6fa3b2e
fb3e427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5af3022
cd1febc
09c8e31
f687325
6fa3b2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f687325
 
 
6fa3b2e
 
 
f687325
 
 
6fa3b2e
 
 
f687325
 
 
 
 
6fa3b2e
 
 
f687325
6fa3b2e
 
 
f687325
 
 
 
 
 
 
 
 
6fa3b2e
 
 
f687325
6fa3b2e
 
 
f687325
 
 
6fa3b2e
f687325
6fa3b2e
09c8e31
5af3022
cd1febc
 
5af3022
 
 
 
 
 
 
 
 
 
 
 
 
12286b2
 
5af3022
 
12286b2
5af3022
 
 
 
 
 
 
cd1febc
5af3022
 
 
 
12286b2
 
5af3022
e7e019f
cd1febc
5af3022
 
 
12286b2
5af3022
 
 
cd1febc
12286b2
09c8e31
 
 
 
 
 
 
12286b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5af3022
 
12286b2
09c8e31
 
5af3022
 
 
cd1febc
fb3e427
 
 
5af3022
 
 
 
fb3e427
 
 
 
 
 
 
cd1febc
09c8e31
fb3e427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09c8e31
f687325
 
23e51a6
 
 
 
 
f687325
23e51a6
f687325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23e51a6
 
f687325
23e51a6
f687325
23e51a6
f687325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23e51a6
 
f687325
23e51a6
f687325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23e51a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09c8e31
fb3e427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09c8e31
 
 
82b4989
09c8e31
 
 
 
 
 
 
 
 
 
fb3e427
82b4989
5af3022
09c8e31
5af3022
09c8e31
 
 
 
 
 
5af3022
09c8e31
 
 
 
 
fb3e427
09c8e31
 
5af3022
 
09c8e31
 
 
5af3022
 
 
 
09c8e31
 
 
5af3022
 
 
 
 
 
 
 
 
09c8e31
5af3022
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb3e427
 
bb2bd2a
 
 
 
 
fb3e427
5af3022
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
(function() {
  // スタイルの動的追加
  const style = document.createElement('style');
  style.textContent = `
.devtools-container {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 300px;
  background-color: #fff;
  border-top: 1px solid #ddd;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.devtools-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background-color: #f5f5f5;
  border-bottom: 1px solid #ddd;
}

.devtools-tabs {
  display: flex;
  gap: 10px;
}

.devtools-tab {
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 3px 3px 0 0;
  background-color: #e0e0e0;
  border: 1px solid #ccc;
  border-bottom: none;
  font-size: 12px;
}

.devtools-tab.active {
  background-color: #fff;
  border-bottom: 1px solid #fff;
  margin-bottom: -1px;
  font-weight: bold;
}

.devtools-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 0 5px;
}

.devtools-content {
  flex: 1;
  overflow: auto;
  position: relative;
}

.devtools-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 10px;
  overflow: auto;
  display: none;
}

.devtools-panel.active {
  display: block;
}

/* Console スタイル */
#console-log {
  white-space: pre-wrap;
  margin: 0;
  line-height: 1.4;
  flex: 1;
  color: #333;
}

.console-input {
  width: 100%;
  background: #f5f5f5;
  border: 1px solid #ddd;
  color: #333;
  padding: 8px;
  margin-top: 10px;
  font-family: monospace;
}

/* Elements スタイル */
.elements-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.dom-tree {
  font-family: monospace;
  flex: 1;
  overflow: auto;
  border-right: 1px solid #ddd;
  padding-right: 10px;
  color: #333;
}

.dom-node {
  margin-left: 15px;
  position: relative;
  line-height: 1.4;
}

.dom-node.selected {
  background: rgba(79, 195, 247, 0.2);
}

.dom-tag {
  color: #0066cc;
  font-weight: bold;
}

.dom-attr {
  color: #d33682;
}

.dom-attr.editable:hover {
  text-decoration: underline;
  cursor: pointer;
}

.dom-text {
  color: #333;
}

.dom-edit-input {
  background: #fff;
  border: 1px solid #4fc3f7;
  padding: 0 2px;
  margin: -1px 0;
  font-family: monospace;
  min-width: 50px;
}

.css-panel {
  flex: 1;
  overflow: auto;
  padding-left: 10px;
}

.css-rule {
  margin-bottom: 15px;
  border: 1px solid #ddd;
  padding: 8px;
  background-color: #f9f9f9;
}

.css-selector {
  color: #0066cc;
  margin-bottom: 5px;
  font-weight: bold;
}

.css-property {
  display: flex;
  margin-bottom: 3px;
}

.css-property-name {
  color: #d33682;
  min-width: 120px;
}

.css-property-value {
  color: #333;
  flex: 1;
}

.css-toggle {
  margin-left: 10px;
  color: #dc322f;
  cursor: pointer;
}

/* Context Menu */
.context-menu {
  position: absolute;
  background: #fff;
  border: 1px solid #ddd;
  z-index: 10000;
  min-width: 200px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  display: none;
}

.context-menu-item {
  padding: 8px 15px;
  cursor: pointer;
  color: #333;
}

.context-menu-item:hover {
  background: #4fc3f7;
  color: #000;
}

/* Storage スタイル */
.storage-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}

.storage-table th, .storage-table td {
  border: 1px solid #ddd;
  padding: 5px;
  text-align: left;
}

.storage-table th {
  background: #f5f5f5;
}

.storage-actions {
  display: flex;
  gap: 5px;
}

.storage-btn {
  background: #4fc3f7;
  border: none;
  padding: 2px 5px;
  cursor: pointer;
  border-radius: 3px;
}

.editable {
  cursor: pointer;
  padding: 2px 5px;
  border: 1px dashed transparent;
}

.editable:hover {
  border-color: #4fc3f7;
}

.add-btn {
  background: #4fc3f7;
  color: #000;
  border: none;
  padding: 5px 10px;
  margin-top: 10px;
  cursor: pointer;
  border-radius: 3px;
}

.json-object {
  color: #268bd2;
}

.json-string {
  color: #2aa198;
}

.json-number {
  color: #d33682;
}

.json-boolean {
  color: #b58900;
}

.json-null {
  color: #6c71c4;
}

`;
  document.head.appendChild(style);

  // グローバル変数
  let contextMenu = null;
  let selectedElement = null;
  let selectedDOMNode = null;
  let activeEditElement = null;

  // 開発者ツールのメイン関数
  function createDevTools() {
    const container = document.createElement('div');
    container.className = 'devtools-container';
    container.id = 'devtools-container';
    container.style.display = 'none';

    // ヘッダー部分
    const header = document.createElement('div');
    header.className = 'devtools-header';

    const tabs = document.createElement('div');
    tabs.className = 'devtools-tabs';

    const consoleTab = createTab('Console', 'console');
    const elementsTab = createTab('Elements', 'elements');
    const storageTab = createTab('Storage', 'storage');

    tabs.appendChild(consoleTab);
    tabs.appendChild(elementsTab);
    tabs.appendChild(storageTab);

    const closeBtn = document.createElement('button');
    closeBtn.className = 'devtools-close';
    closeBtn.textContent = '×';
    closeBtn.onclick = toggleDevTools;

    header.appendChild(tabs);
    header.appendChild(closeBtn);

    // コンテンツ部分
    const content = document.createElement('div');
    content.className = 'devtools-content';

    const consolePanel = createConsolePanel();
    const elementsPanel = createElementsPanel();
    const storagePanel = createStoragePanel();

    content.appendChild(consolePanel);
    content.appendChild(elementsPanel);
    content.appendChild(storagePanel);

    container.appendChild(header);
    container.appendChild(content);

    document.body.appendChild(container);

    // コンテキストメニュー作成
    createContextMenu();

    // タブ切り替え機能
    function createTab(name, panelId) {
      const tab = document.createElement('div');
      tab.className = 'devtools-tab';
      tab.textContent = name;
      tab.onclick = () => {
        document.querySelectorAll('.devtools-tab').forEach(t => t.classList.remove('active'));
        document.querySelectorAll('.devtools-panel').forEach(p => p.classList.remove('active'));
        tab.classList.add('active');
        document.getElementById(panelId + '-panel').classList.add('active');
      };
      return tab;
    }

    elementsTab.click();
  }

  // コンテキストメニュー作成
  function createContextMenu() {
    contextMenu = document.createElement('div');
    contextMenu.className = 'context-menu';
    contextMenu.innerHTML = `
      <div class="context-menu-item" data-action="edit-html">HTMLとして編集</div>
      <div class="context-menu-item" data-action="add-attribute">属性を追加</div>
      <div class="context-menu-item" data-action="edit-element">要素を編集</div>
      <div class="context-menu-item" data-action="duplicate">要素を複製</div>
      <div class="context-menu-item" data-action="remove">要素を削除</div>
      <div class="context-menu-item" data-action="toggle-visibility">要素を非表示</div>
      <div class="context-menu-item" data-action="force-state">状態を強制</div>
    `;
    document.body.appendChild(contextMenu);

    contextMenu.querySelectorAll('.context-menu-item').forEach(item => {
      item.addEventListener('click', (e) => {
        const action = e.target.getAttribute('data-action');
        handleContextMenuAction(action);
        contextMenu.style.display = 'none';
      });
    });

    document.addEventListener('click', (e) => {
      if (e.target !== contextMenu && !contextMenu.contains(e.target)) {
        contextMenu.style.display = 'none';
      }
    });
  }
  function createStoragePanel() {
    const panel = document.createElement('div');
    panel.className = 'devtools-panel';
    panel.id = 'storage-panel';

    // LocalStorage表示
    const localStorageTitle = document.createElement('h3');
    localStorageTitle.textContent = 'Local Storage';
    panel.appendChild(localStorageTitle);

    const localStorageTable = document.createElement('table');
    localStorageTable.className = 'storage-table';
    panel.appendChild(localStorageTable);

    const addLocalStorageBtn = document.createElement('button');
    addLocalStorageBtn.className = 'add-btn';
    addLocalStorageBtn.textContent = '+ Local Storageに追加';
    addLocalStorageBtn.onclick = () => {
      const key = prompt('キー名を入力');
      if (key) {
        const value = prompt('値を入力');
        localStorage.setItem(key, value);
        renderStorage();
      }
    };
    panel.appendChild(addLocalStorageBtn);

    // SessionStorage表示
    const sessionStorageTitle = document.createElement('h3');
    sessionStorageTitle.style.marginTop = '20px';
    sessionStorageTitle.textContent = 'Session Storage';
    panel.appendChild(sessionStorageTitle);

    const sessionStorageTable = document.createElement('table');
    sessionStorageTable.className = 'storage-table';
    panel.appendChild(sessionStorageTable);

    const addSessionStorageBtn = document.createElement('button');
    addSessionStorageBtn.className = 'add-btn';
    addSessionStorageBtn.textContent = '+ Session Storageに追加';
    addSessionStorageBtn.onclick = () => {
      const key = prompt('キー名を入力');
      if (key) {
        const value = prompt('値を入力');
        sessionStorage.setItem(key, value);
        renderStorage();
      }
    };
    panel.appendChild(addSessionStorageBtn);

    // Cookie表示
    const cookiesTitle = document.createElement('h3');
    cookiesTitle.style.marginTop = '20px';
    cookiesTitle.textContent = 'Cookies';
    panel.appendChild(cookiesTitle);

    const cookiesTable = document.createElement('table');
    cookiesTable.className = 'storage-table';
    panel.appendChild(cookiesTable);

    const addCookieBtn = document.createElement('button');
    addCookieBtn.className = 'add-btn';
    addCookieBtn.textContent = '+ Cookieに追加';
    addCookieBtn.onclick = () => {
      const name = prompt('Cookie名を入力');
      if (name) {
        const value = prompt('値を入力');
        document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; path=/`;
        renderStorage();
      }
    };
    panel.appendChild(addCookieBtn);

    // ストレージを表示する関数
    function renderStorage() {
      renderTable(localStorageTable, localStorage, 'local');
      renderTable(sessionStorageTable, sessionStorage, 'session');
      renderCookiesTable(cookiesTable);
    }

    function renderTable(tableElement, storage, type) {
      tableElement.innerHTML = `
        <thead>
          <tr>
            <th>Key</th>
            <th>Value</th>
            <th>Actions</th>
          </tr>
        </thead>
        <tbody></tbody>
      `;

      const tbody = tableElement.querySelector('tbody');
      
      for (let i = 0; i < storage.length; i++) {
        const key = storage.key(i);
        const value = storage.getItem(key);
        
        const row = document.createElement('tr');
        
        const keyCell = document.createElement('td');
        const keySpan = document.createElement('span');
        keySpan.className = 'editable';
        keySpan.textContent = key;
        keySpan.onclick = () => {
          const newKey = prompt('新しいキー名を入力', key);
          if (newKey && newKey !== key) {
            storage.setItem(newKey, value);
            storage.removeItem(key);
            renderStorage();
          }
        };
        keyCell.appendChild(keySpan);
        
        const valueCell = document.createElement('td');
        const valueSpan = document.createElement('span');
        valueSpan.className = 'editable';
        valueSpan.textContent = value;
        valueSpan.onclick = () => {
          const newValue = prompt('新しい値を入力', value);
          if (newValue !== null) {
            storage.setItem(key, newValue);
            renderStorage();
          }
        };
        valueCell.appendChild(valueSpan);
        
        const actionsCell = document.createElement('td');
        actionsCell.className = 'storage-actions';
        
        const deleteBtn = document.createElement('button');
        deleteBtn.className = 'storage-btn';
        deleteBtn.textContent = 'Delete';
        deleteBtn.onclick = () => {
          storage.removeItem(key);
          renderStorage();
        };
        
        actionsCell.appendChild(deleteBtn);
        
        row.appendChild(keyCell);
        row.appendChild(valueCell);
        row.appendChild(actionsCell);
        
        tbody.appendChild(row);
      }
    }

    function renderCookiesTable(tableElement) {
      tableElement.innerHTML = `
        <thead>
          <tr>
            <th>Name</th>
            <th>Value</th>
            <th>Actions</th>
          </tr>
        </thead>
        <tbody></tbody>
      `;

      const tbody = tableElement.querySelector('tbody');
      
      document.cookie.split(';').forEach(cookie => {
        if (!cookie.trim()) return;
        
        const [name, ...valueParts] = cookie.split('=');
        const decodedName = decodeURIComponent(name.trim());
        const value = valueParts.join('=').trim();
        
        const row = document.createElement('tr');
        
        const nameCell = document.createElement('td');
        const nameSpan = document.createElement('span');
        nameSpan.className = 'editable';
        nameSpan.textContent = decodedName;
        nameSpan.onclick = () => {
          const newName = prompt('新しい名前を入力', decodedName);
          if (newName && newName !== decodedName) {
            const newValue = prompt('新しい値を入力', decodeURIComponent(value));
            if (newValue !== null) {
              document.cookie = `${encodeURIComponent(newName)}=${encodeURIComponent(newValue)}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
              document.cookie = `${name.trim()}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
              renderStorage();
            }
          }
        };
        nameCell.appendChild(nameSpan);
        
        const valueCell = document.createElement('td');
        const valueSpan = document.createElement('span');
        valueSpan.className = 'editable';
        valueSpan.textContent = decodeURIComponent(value);
        valueSpan.onclick = () => {
          const newValue = prompt('新しい値を入力', decodeURIComponent(value));
          if (newValue !== null) {
            document.cookie = `${name.trim()}=${encodeURIComponent(newValue)}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
            renderStorage();
          }
        };
        valueCell.appendChild(valueSpan);
        
        const actionsCell = document.createElement('td');
        actionsCell.className = 'storage-actions';
        
        const deleteBtn = document.createElement('button');
        deleteBtn.className = 'storage-btn';
        deleteBtn.textContent = 'Delete';
        deleteBtn.onclick = () => {
          document.cookie = `${name.trim()}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
          renderStorage();
        };
        
        actionsCell.appendChild(deleteBtn);
        
        row.appendChild(nameCell);
        row.appendChild(valueCell);
        row.appendChild(actionsCell);
        
        tbody.appendChild(row);
      });
    }

    // 初期表示
    renderStorage();

    return panel;
  }
  // コンテキストメニューアクション処理
  function handleContextMenuAction(action) {
    if (!selectedElement) return;

    switch (action) {
        case 'edit-html':
            // document.documentElement(html要素)は編集不可
            if (selectedElement === document.documentElement) {
                alert('ルートHTML要素は直接編集できません');
                return;
            }
            startInlineEdit(selectedDOMNode, selectedElement.outerHTML, (newValue) => {
                try {
                    selectedElement.outerHTML = newValue;
                    refreshElementsPanel();
                } catch (e) {
                    alert('この要素は編集できません: ' + e.message);
                }
            });
        break;
      case 'add-attribute':
        const attrName = prompt('属性名を入力');
        if (attrName) {
          const attrValue = prompt('属性値を入力');
          selectedElement.setAttribute(attrName, attrValue || '');
          refreshElementsPanel();
        }
        break;
      case 'edit-element':
        startInlineEdit(selectedDOMNode.querySelector('.dom-tag'), selectedElement.tagName.toLowerCase(), (newValue) => {
          const newElement = document.createElement(newValue);
          Array.from(selectedElement.attributes).forEach(attr => {
            newElement.setAttribute(attr.name, attr.value);
          });
          newElement.innerHTML = selectedElement.innerHTML;
          selectedElement.parentNode.replaceChild(newElement, selectedElement);
          selectedElement = newElement;
          refreshElementsPanel();
        });
        break;
      case 'duplicate':
        const clone = selectedElement.cloneNode(true);
        selectedElement.parentNode.insertBefore(clone, selectedElement.nextSibling);
        refreshElementsPanel();
        break;
      case 'remove':
        if (confirm('要素を削除しますか?')) {
          selectedElement.parentNode.removeChild(selectedElement);
          refreshElementsPanel();
        }
        break;
      case 'toggle-visibility':
        if (selectedElement.style.display === 'none') {
          selectedElement.style.display = '';
        } else {
          selectedElement.style.display = 'none';
        }
        refreshElementsPanel();
        break;
      case 'force-state':
        const state = prompt('強制する状態を入力 (例: hover, active, focus)', 'hover');
        if (state) {
          selectedElement.classList.remove('force-hover', 'force-active', 'force-focus', 
                                         'force-focus-within', 'force-focus-visible', 'force-target');
          selectedElement.classList.add(`force-${state}`);
          refreshElementsPanel();
        }
        break;
    }
  }

  // インライン編集関数
function startInlineEdit(element, initialValue, callback) {
    if (activeEditElement) return;
    
    const originalValue = element.textContent;
    const rect = element.getBoundingClientRect();
    
    const input = document.createElement('input');
    input.className = 'dom-edit-input';
    input.value = initialValue || originalValue;
    input.style.position = 'absolute';
    input.style.left = `${rect.left}px`;
    input.style.top = `${rect.top}px`;
    input.style.width = `${rect.width + 20}px`;
    
    document.body.appendChild(input);
    input.focus();
    input.select();
    
    activeEditElement = {
        element: element,
        input: input,
        callback: callback
    };
    
    const clickOutsideHandler = (e) => {
        if (!input.contains(e.target)) {
            finishInlineEdit();
        }
    };
    
    input.addEventListener('keydown', (e) => {
        if (e.key === 'Enter') {
            finishInlineEdit();
        } else if (e.key === 'Escape') {
            cancelInlineEdit();
        }
    });
    
    setTimeout(() => {
        document.addEventListener('click', clickOutsideHandler);
    }, 0);
    
    function finishInlineEdit() {
        try {
            if (input.value !== originalValue && callback) {
                callback(input.value);
            }
        } catch (e) {
            alert('編集に失敗しました: ' + e.message);
        } finally {
            cleanup();
        }
    }
    
    function cancelInlineEdit() {
        cleanup();
    }
    
    function cleanup() {
        document.removeEventListener('click', clickOutsideHandler);
        input.remove();
        activeEditElement = null;
    }
}

  // Consoleパネル作成
  function createConsolePanel() {
    const panel = document.createElement('div');
    panel.className = 'devtools-panel';
    panel.id = 'console-panel';

    const log = document.createElement('div');
    log.id = 'console-log';

    const input = document.createElement('input');
    input.className = 'console-input';
    input.placeholder = 'ここにJavaScriptを入力... (Enterで実行)';
    input.onkeypress = (e) => {
      if (e.key === 'Enter') {
        try {
          const result = eval(e.target.value);
          if (result !== undefined) {
            logMessage('> ' + e.target.value, '#0066cc');
            logMessage('← ' + formatOutput(result), '#2aa198');
          }
        } catch (err) {
          logMessage(err.message, '#dc322f');
        }
        e.target.value = '';
      }
    };

    panel.appendChild(log);
    panel.appendChild(input);

    ['log', 'error', 'warn'].forEach(method => {
      const original = console[method];
      console[method] = (...args) => {
        original.apply(console, args);
        const color = method === 'error' ? '#dc322f' : method === 'warn' ? '#b58900' : '#586e75';
        logMessage(args.map(arg => formatOutput(arg)).join(' '), color);
      };
    });

    function logMessage(message, color) {
      const line = document.createElement('div');
      line.style.color = color;
      line.innerHTML = message;
      log.appendChild(line);
      log.scrollTop = log.scrollHeight;
    }

    function formatOutput(output) {
      if (output === null) return '<span class="json-null">null</span>';
      if (output === undefined) return '<span class="json-null">undefined</span>';
      if (typeof output === 'boolean') return `<span class="json-boolean">${output}</span>`;
      if (typeof output === 'number') return `<span class="json-number">${output}</span>`;
      if (typeof output === 'string') return `<span class="json-string">"${output}"</span>`;
      if (typeof output === 'function') return `<span class="json-object">function ${output.name}() { ... }</span>`;
      if (Array.isArray(output)) return `<span class="json-object">[${output.map(formatOutput).join(', ')}]</span>`;
      if (typeof output === 'object') {
        try {
          return `<span class="json-object">${JSON.stringify(output, null, 2)
            .replace(/"([^"]+)":/g, '<span class="json-string">"$1"</span>:')
            .replace(/"([^"]+)"/g, '<span class="json-string">"$1"</span>')
            .replace(/\b(true|false)\b/g, '<span class="json-boolean">$1</span>')
            .replace(/\b(null)\b/g, '<span class="json-null">$1</span>')
            .replace(/\b(\d+)\b/g, '<span class="json-number">$1</span>')}</span>`;
        } catch (e) {
          return `<span class="json-object">${output.toString()}</span>`;
        }
      }
      return output;
    }

    return panel;
  }

  // Elementsパネル作成
  function createElementsPanel() {
    const panel = document.createElement('div');
    panel.className = 'devtools-panel';
    panel.id = 'elements-panel';

    const container = document.createElement('div');
    container.className = 'elements-container';

    const tree = document.createElement('div');
    tree.className = 'dom-tree';
    tree.id = 'dom-tree';

    const cssPanel = document.createElement('div');
    cssPanel.className = 'css-panel';
    cssPanel.id = 'css-panel';

    container.appendChild(tree);
    container.appendChild(cssPanel);
    panel.appendChild(container);

    // CSSパネル更新関数
    function updateCSSPanel(element) {
      const cssPanel = document.getElementById('css-panel');
      cssPanel.innerHTML = '';
      
      if (!element) return;
      
      if (element.style.length > 0) {
        const inlineRule = document.createElement('div');
        inlineRule.className = 'css-rule';
        
        const selector = document.createElement('div');
        selector.className = 'css-selector';
        selector.textContent = 'インラインスタイル';
        inlineRule.appendChild(selector);
        
        for (let i = 0; i < element.style.length; i++) {
          const propName = element.style[i];
          const propValue = element.style[propName];
          
          const propDiv = document.createElement('div');
          propDiv.className = 'css-property';
          
          const nameSpan = document.createElement('span');
          nameSpan.className = 'css-property-name editable';
          nameSpan.textContent = propName;
          nameSpan.onclick = () => editCSSProperty(element, propName, 'style');
          
          const valueSpan = document.createElement('span');
          valueSpan.className = 'css-property-value editable';
          valueSpan.textContent = propValue;
          valueSpan.onclick = () => editCSSProperty(element, propName, 'style');
          
          const toggleSpan = document.createElement('span');
          toggleSpan.className = 'css-toggle';
          toggleSpan.textContent = '×';
          toggleSpan.title = 'プロパティを無効化';
          toggleSpan.onclick = () => {
            element.style[propName] = '';
            updateCSSPanel(element);
          };
          
          propDiv.appendChild(nameSpan);
          propDiv.appendChild(valueSpan);
          propDiv.appendChild(toggleSpan);
          inlineRule.appendChild(propDiv);
        }
        
        cssPanel.appendChild(inlineRule);
      }
      
      const computedStyles = window.getComputedStyle(element);
      const computedRule = document.createElement('div');
      computedRule.className = 'css-rule';
      
      const computedSelector = document.createElement('div');
      computedSelector.className = 'css-selector';
      computedSelector.textContent = '計算されたスタイル';
      computedRule.appendChild(computedSelector);
      
      const importantProps = [
        'display', 'position', 'width', 'height', 'margin', 'padding', 
        'color', 'background', 'border', 'font', 'flex', 'grid'
      ];
      
      importantProps.forEach(prop => {
        const value = computedStyles[prop];
        
        const propDiv = document.createElement('div');
        propDiv.className = 'css-property';
        
        const nameSpan = document.createElement('span');
        nameSpan.className = 'css-property-name';
        nameSpan.textContent = prop;
        
        const valueSpan = document.createElement('span');
        valueSpan.className = 'css-property-value';
        valueSpan.textContent = value;
        
        propDiv.appendChild(nameSpan);
        propDiv.appendChild(valueSpan);
        computedRule.appendChild(propDiv);
      });
      
      cssPanel.appendChild(computedRule);
    }

    // DOMツリー構築
function buildDOMTree(node, parentElement, depth = 0) {
    if (node.nodeType === Node.ELEMENT_NODE) {
        const element = document.createElement('div');
        element.className = 'dom-node';
        element.style.marginLeft = `${depth * 15}px`;
        element.dataset.elementId = node.id || Math.random().toString(36).substr(2, 9);

        // 右クリックイベント
        element.oncontextmenu = (e) => {
            e.preventDefault();
            selectedElement = node;
            selectedDOMNode = element;
            
            document.querySelectorAll('.dom-node').forEach(el => el.classList.remove('selected'));
            element.classList.add('selected');
            
            // HTML要素にはコンテキストメニューを表示しない
            if (node !== document.documentElement) {
                contextMenu.style.display = 'block';
                contextMenu.style.left = `${e.pageX}px`;
                contextMenu.style.top = `${e.pageY}px`;
            }
            
            updateCSSPanel(node);
        };

        // タグ名(HTML要素は編集不可)
        const tag = document.createElement('span');
        tag.className = 'dom-tag';
        tag.textContent = `<${node.tagName.toLowerCase()}`;
        
        if (node !== document.documentElement) {
            tag.classList.add('editable');
            tag.onclick = (e) => {
                e.stopPropagation();
                startInlineEdit(tag, node.tagName.toLowerCase(), (newValue) => {
                    const newElement = document.createElement(newValue);
                    Array.from(node.attributes).forEach(attr => {
                        newElement.setAttribute(attr.name, attr.value);
                    });
                    newElement.innerHTML = node.innerHTML;
                    node.parentNode.replaceChild(newElement, node);
                    selectedElement = newElement;
                    refreshElementsPanel();
                });
            };
        }
        
        element.appendChild(tag);

        // 属性(HTML要素は編集不可)
        Array.from(node.attributes).forEach(attr => {
            const attrSpan = document.createElement('span');
            attrSpan.className = 'dom-attr';
            attrSpan.textContent = ` ${attr.name}="${attr.value}"`;
            
            if (node !== document.documentElement) {
                attrSpan.classList.add('editable');
                attrSpan.onclick = (e) => {
                    e.stopPropagation();
                    startInlineEdit(attrSpan, attr.value, (newValue) => {
                        node.setAttribute(attr.name, newValue);
                        refreshElementsPanel();
                    });
                };
            }
            
            element.appendChild(attrSpan);
        });

        element.appendChild(document.createTextNode('>'));

        if (node.childNodes.length > 0) {
          node.childNodes.forEach(child => {
            buildDOMTree(child, element, depth + 1);
          });
        }

        if (node.childNodes.length > 0 || node.tagName.toLowerCase() !== 'br') {
          const closeTag = document.createElement('div');
          closeTag.style.marginLeft = `${depth * 15}px`;
          closeTag.innerHTML = `<span class="dom-tag">&lt;/${node.tagName.toLowerCase()}&gt;</span>`;
          element.appendChild(closeTag);
        }

        parentElement.appendChild(element);
      } else if (node.nodeType === Node.TEXT_NODE && node.textContent.trim()) {
        const text = document.createElement('div');
        text.style.marginLeft = `${depth * 15}px`;
        text.className = 'dom-text editable';
        text.textContent = `"${node.textContent.trim()}"`;
        text.onclick = (e) => {
          e.stopPropagation();
          startInlineEdit(text, node.textContent.trim(), (newValue) => {
            node.textContent = newValue;
            refreshElementsPanel();
          });
        };
        parentElement.appendChild(text);
      }
    }

    // CSSプロパティ編集
    function editCSSProperty(element, propName, styleType) {
      let currentValue = '';
      
      if (styleType === 'style') {
        currentValue = element.style[propName];
      }
      
      const newValue = prompt(`${propName} の新しい値を入力`, currentValue);
      
      if (newValue !== null) {
        if (styleType === 'style') {
          element.style[propName] = newValue;
        }
        
        updateCSSPanel(element);
        refreshElementsPanel();
      }
    }

    // 要素パネル更新
    function refreshElementsPanel() {
      let tree = document.getElementById('dom-tree');
      
      if (!tree) {
        const panel = document.getElementById('elements-panel');
        if (panel) {
          const container = panel.querySelector('.elements-container');
          if (container) {
            tree = document.createElement('div');
            tree.className = 'dom-tree';
            tree.id = 'dom-tree';
            container.insertBefore(tree, container.querySelector('.css-panel'));
          }
        }
      }
      
      if (!tree) return;
      
      tree.innerHTML = '';
      buildDOMTree(document.documentElement, tree);
      
      if (selectedElement) {
        const elementId = selectedElement.id || Array.from(selectedElement.attributes)
          .find(attr => attr.name.startsWith('data-element-id'))?.value;
        
        if (elementId) {
          const node = document.querySelector(`[data-element-id="${elementId}"]`);
          if (node) {
            node.classList.add('selected');
            updateCSSPanel(selectedElement);
          }
        }
      }
    }

    setTimeout(() => {
      refreshElementsPanel();
    }, 0);

    return panel;
  }

  // Storageパネル作成 (前回と同じなので省略)

  // 開発者ツール表示/非表示
  function toggleDevTools() {
    const container = document.getElementById('devtools-container');
    if (container.style.display === 'none') {
      container.style.display = 'flex';
    } else {
      container.style.display = 'none';
    }
  }

  // 開くボタン作成
  function createOpenButton() {
    const button = document.createElement('button');
    button.id = 'open-devtools-btn';
    button.textContent = '開発者ツールを開く';
    button.style.position = 'fixed';
    button.style.bottom = '10px';
    button.style.right = '10px';
    button.style.padding = '8px 16px';
    button.style.background = '#4fc3f7';
    button.style.color = '#000';
    button.style.border = 'none';
    button.style.borderRadius = '4px';
    button.style.cursor = 'pointer';
    button.style.zIndex = '9998';
    button.onclick = toggleDevTools;

    document.body.appendChild(button);
  }

  // 初期化
  document.addEventListener('DOMContentLoaded', function() {
    createDevTools();
    createOpenButton();
    console.log('開発者ツールが初期化されました');
    console.log('このコンソールでJavaScriptを実行できます');
  });
})();