soiz1 commited on
Commit
af1c1d6
·
verified ·
1 Parent(s): 09c8e31

Update dev-tools.js

Browse files
Files changed (1) hide show
  1. dev-tools.js +226 -0
dev-tools.js CHANGED
@@ -386,7 +386,233 @@
386
  }
387
  });
388
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
 
 
 
 
 
 
390
  // コンテキストメニューアクション処理
391
  function handleContextMenuAction(action) {
392
  if (!selectedElement) return;
 
386
  }
387
  });
388
  }
389
+ function createStoragePanel() {
390
+ const panel = document.createElement('div');
391
+ panel.className = 'devtools-panel';
392
+ panel.id = 'storage-panel';
393
+
394
+ // LocalStorage表示
395
+ const localStorageTitle = document.createElement('h3');
396
+ localStorageTitle.textContent = 'Local Storage';
397
+ panel.appendChild(localStorageTitle);
398
+
399
+ const localStorageTable = document.createElement('table');
400
+ localStorageTable.className = 'storage-table';
401
+ panel.appendChild(localStorageTable);
402
+
403
+ const addLocalStorageBtn = document.createElement('button');
404
+ addLocalStorageBtn.className = 'add-btn';
405
+ addLocalStorageBtn.textContent = '+ Local Storageに追加';
406
+ addLocalStorageBtn.onclick = () => {
407
+ const key = prompt('キー名を入力');
408
+ if (key) {
409
+ const value = prompt('値を入力');
410
+ localStorage.setItem(key, value);
411
+ renderStorage();
412
+ }
413
+ };
414
+ panel.appendChild(addLocalStorageBtn);
415
+
416
+ // SessionStorage表示
417
+ const sessionStorageTitle = document.createElement('h3');
418
+ sessionStorageTitle.style.marginTop = '20px';
419
+ sessionStorageTitle.textContent = 'Session Storage';
420
+ panel.appendChild(sessionStorageTitle);
421
+
422
+ const sessionStorageTable = document.createElement('table');
423
+ sessionStorageTable.className = 'storage-table';
424
+ panel.appendChild(sessionStorageTable);
425
+
426
+ const addSessionStorageBtn = document.createElement('button');
427
+ addSessionStorageBtn.className = 'add-btn';
428
+ addSessionStorageBtn.textContent = '+ Session Storageに追加';
429
+ addSessionStorageBtn.onclick = () => {
430
+ const key = prompt('キー名を入力');
431
+ if (key) {
432
+ const value = prompt('値を入力');
433
+ sessionStorage.setItem(key, value);
434
+ renderStorage();
435
+ }
436
+ };
437
+ panel.appendChild(addSessionStorageBtn);
438
+
439
+ // Cookie表示
440
+ const cookiesTitle = document.createElement('h3');
441
+ cookiesTitle.style.marginTop = '20px';
442
+ cookiesTitle.textContent = 'Cookies';
443
+ panel.appendChild(cookiesTitle);
444
+
445
+ const cookiesTable = document.createElement('table');
446
+ cookiesTable.className = 'storage-table';
447
+ panel.appendChild(cookiesTable);
448
+
449
+ const addCookieBtn = document.createElement('button');
450
+ addCookieBtn.className = 'add-btn';
451
+ addCookieBtn.textContent = '+ Cookieに追加';
452
+ addCookieBtn.onclick = () => {
453
+ const name = prompt('Cookie名を入力');
454
+ if (name) {
455
+ const value = prompt('値を入力');
456
+ document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; path=/`;
457
+ renderStorage();
458
+ }
459
+ };
460
+ panel.appendChild(addCookieBtn);
461
+
462
+ // ストレージを表示する関数
463
+ function renderStorage() {
464
+ renderTable(localStorageTable, localStorage, 'local');
465
+ renderTable(sessionStorageTable, sessionStorage, 'session');
466
+ renderCookiesTable(cookiesTable);
467
+ }
468
+
469
+ function renderTable(tableElement, storage, type) {
470
+ tableElement.innerHTML = `
471
+ <thead>
472
+ <tr>
473
+ <th>Key</th>
474
+ <th>Value</th>
475
+ <th>Actions</th>
476
+ </tr>
477
+ </thead>
478
+ <tbody></tbody>
479
+ `;
480
+
481
+ const tbody = tableElement.querySelector('tbody');
482
+
483
+ for (let i = 0; i < storage.length; i++) {
484
+ const key = storage.key(i);
485
+ const value = storage.getItem(key);
486
+
487
+ const row = document.createElement('tr');
488
+
489
+ const keyCell = document.createElement('td');
490
+ const keySpan = document.createElement('span');
491
+ keySpan.className = 'editable';
492
+ keySpan.textContent = key;
493
+ keySpan.onclick = () => {
494
+ const newKey = prompt('新しいキー名を入力', key);
495
+ if (newKey && newKey !== key) {
496
+ storage.setItem(newKey, value);
497
+ storage.removeItem(key);
498
+ renderStorage();
499
+ }
500
+ };
501
+ keyCell.appendChild(keySpan);
502
+
503
+ const valueCell = document.createElement('td');
504
+ const valueSpan = document.createElement('span');
505
+ valueSpan.className = 'editable';
506
+ valueSpan.textContent = value;
507
+ valueSpan.onclick = () => {
508
+ const newValue = prompt('新しい値を入力', value);
509
+ if (newValue !== null) {
510
+ storage.setItem(key, newValue);
511
+ renderStorage();
512
+ }
513
+ };
514
+ valueCell.appendChild(valueSpan);
515
+
516
+ const actionsCell = document.createElement('td');
517
+ actionsCell.className = 'storage-actions';
518
+
519
+ const deleteBtn = document.createElement('button');
520
+ deleteBtn.className = 'storage-btn';
521
+ deleteBtn.textContent = 'Delete';
522
+ deleteBtn.onclick = () => {
523
+ storage.removeItem(key);
524
+ renderStorage();
525
+ };
526
+
527
+ actionsCell.appendChild(deleteBtn);
528
+
529
+ row.appendChild(keyCell);
530
+ row.appendChild(valueCell);
531
+ row.appendChild(actionsCell);
532
+
533
+ tbody.appendChild(row);
534
+ }
535
+ }
536
+
537
+ function renderCookiesTable(tableElement) {
538
+ tableElement.innerHTML = `
539
+ <thead>
540
+ <tr>
541
+ <th>Name</th>
542
+ <th>Value</th>
543
+ <th>Actions</th>
544
+ </tr>
545
+ </thead>
546
+ <tbody></tbody>
547
+ `;
548
+
549
+ const tbody = tableElement.querySelector('tbody');
550
+
551
+ document.cookie.split(';').forEach(cookie => {
552
+ if (!cookie.trim()) return;
553
+
554
+ const [name, ...valueParts] = cookie.split('=');
555
+ const decodedName = decodeURIComponent(name.trim());
556
+ const value = valueParts.join('=').trim();
557
+
558
+ const row = document.createElement('tr');
559
+
560
+ const nameCell = document.createElement('td');
561
+ const nameSpan = document.createElement('span');
562
+ nameSpan.className = 'editable';
563
+ nameSpan.textContent = decodedName;
564
+ nameSpan.onclick = () => {
565
+ const newName = prompt('新しい名前を入力', decodedName);
566
+ if (newName && newName !== decodedName) {
567
+ const newValue = prompt('新しい値を入力', decodeURIComponent(value));
568
+ if (newValue !== null) {
569
+ document.cookie = `${encodeURIComponent(newName)}=${encodeURIComponent(newValue)}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
570
+ document.cookie = `${name.trim()}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
571
+ renderStorage();
572
+ }
573
+ }
574
+ };
575
+ nameCell.appendChild(nameSpan);
576
+
577
+ const valueCell = document.createElement('td');
578
+ const valueSpan = document.createElement('span');
579
+ valueSpan.className = 'editable';
580
+ valueSpan.textContent = decodeURIComponent(value);
581
+ valueSpan.onclick = () => {
582
+ const newValue = prompt('新しい値を入力', decodeURIComponent(value));
583
+ if (newValue !== null) {
584
+ document.cookie = `${name.trim()}=${encodeURIComponent(newValue)}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
585
+ renderStorage();
586
+ }
587
+ };
588
+ valueCell.appendChild(valueSpan);
589
+
590
+ const actionsCell = document.createElement('td');
591
+ actionsCell.className = 'storage-actions';
592
+
593
+ const deleteBtn = document.createElement('button');
594
+ deleteBtn.className = 'storage-btn';
595
+ deleteBtn.textContent = 'Delete';
596
+ deleteBtn.onclick = () => {
597
+ document.cookie = `${name.trim()}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
598
+ renderStorage();
599
+ };
600
+
601
+ actionsCell.appendChild(deleteBtn);
602
+
603
+ row.appendChild(nameCell);
604
+ row.appendChild(valueCell);
605
+ row.appendChild(actionsCell);
606
+
607
+ tbody.appendChild(row);
608
+ });
609
+ }
610
 
611
+ // 初期表示
612
+ renderStorage();
613
+
614
+ return panel;
615
+ }
616
  // コンテキストメニューアクション処理
617
  function handleContextMenuAction(action) {
618
  if (!selectedElement) return;