soiz1 commited on
Commit
cd1febc
·
verified ·
1 Parent(s): e7e019f

Update dev-tools.js

Browse files
Files changed (1) hide show
  1. dev-tools.js +195 -135
dev-tools.js CHANGED
@@ -1,141 +1,201 @@
1
  // dev-tools.js
2
  document.addEventListener('DOMContentLoaded', () => {
3
- // 開発者ツール起動ボタン
4
- const openButton = document.createElement('button');
5
- openButton.textContent = '開発者ツールを開く';
6
- openButton.style.position = 'fixed';
7
- openButton.style.top = '10px';
8
- openButton.style.right = '10px';
9
- document.body.appendChild(openButton);
10
-
11
- // 開発者ツールコンテナ
12
- const devToolsContainer = document.createElement('div');
13
- devToolsContainer.style.cssText = `
14
- position: fixed;
15
- bottom: 0;
16
- left: 0;
17
- right: 0;
18
- height: 400px;
19
- background: #242424;
20
- color: #fff;
21
- font-family: monospace;
22
- display: none;
23
- border-top: 2px solid #888;
24
- flex-direction: column;
25
- `;
26
-
27
- // タブバー
28
- const tabBar = document.createElement('div');
29
- tabBar.style.display = 'flex';
30
- tabBar.style.padding = '5px';
31
- tabBar.style.gap = '10px';
32
- tabBar.style.background = '#1a1a1a';
33
-
34
- // タブボタン
35
- const tabs = ['Console', 'Elements', 'Storage'];
36
- const contentAreas = {};
37
-
38
- tabs.forEach(tabName => {
39
- const tabButton = document.createElement('button');
40
- tabButton.textContent = tabName;
41
- tabButton.addEventListener('click', () => {
42
- Object.values(contentAreas).forEach(area => area.style.display = 'none');
43
- contentAreas[tabName].style.display = 'block';
44
- tabButton.classList.add('active');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  });
46
- tabBar.appendChild(tabButton);
47
-
48
- const content = document.createElement('div');
49
- content.style.display = 'none';
50
- content.style.flexGrow = '1';
51
- content.style.overflow = 'auto';
52
- contentAreas[tabName] = content;
53
- devToolsContainer.appendChild(content);
54
- });
55
-
56
- // Consoleタブ
57
- const consoleContent = contentAreas['Console'];
58
- consoleContent.innerHTML = `
59
- <input type="text" id="console-input" placeholder="JavaScriptを入力"
60
- style="width: 100%; padding: 5px; background: #333; color: #fff; border: none;">
61
- <pre id="console-output" style="padding: 10px; margin: 0;"></pre>
62
- `;
63
-
64
- // Consoleログのキャプチャ
65
- const originalConsoleLog = console.log;
66
- const consoleOutput = consoleContent.querySelector('#console-output');
67
-
68
- console.log = (...args) => {
69
- consoleOutput.textContent += args.join(' ') + '\n';
70
- originalConsoleLog(...args);
71
- };
72
-
73
- // JavaScript実行
74
- consoleContent.querySelector('#console-input').addEventListener('keypress', e => {
75
- if (e.key === 'Enter') {
76
- try {
77
- eval(e.target.value);
78
- } catch (err) {
79
- console.log('Error:', err.message);
80
- }
81
- e.target.value = '';
 
 
 
82
  }
83
- });
84
-
85
- // Elementsタブ
86
- const elementsContent = contentAreas['Elements'];
87
- elementsContent.innerHTML = '<div class="dom-tree"></div>';
88
-
89
- function buildDOMTree(element, parent) {
90
- const div = document.createElement('div');
91
- div.textContent = '<' + element.tagName.toLowerCase() + '>';
92
- div.style.paddingLeft = '20px';
93
-
94
- Array.from(element.children).forEach(child => {
95
- buildDOMTree(child, div);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  });
97
-
98
- parent.appendChild(div);
99
- }
100
-
101
- buildDOMTree(document.documentElement, elementsContent.querySelector('.dom-tree'));
102
-
103
- // Storageタブ
104
- const storageContent = contentAreas['Storage'];
105
- storageContent.innerHTML = `
106
- <div style="padding: 10px;">
107
- <h3>Local Storage</h3>
108
- <pre id="local-storage"></pre>
109
- <button id="clear-storage">Clear Local Storage</button>
110
-
111
- <h3>Cookies</h3>
112
- <pre id="cookies"></pre>
113
- </div>
114
- `;
115
-
116
- // ストレージ表示更新
117
- function updateStorageDisplay() {
118
- storageContent.querySelector('#local-storage').textContent =
119
- JSON.stringify(localStorage, null, 2);
120
- storageContent.querySelector('#cookies').textContent =
121
- document.cookie;
122
- }
123
-
124
- storageContent.querySelector('#clear-storage').addEventListener('click', () => {
125
- localStorage.clear();
126
- updateStorageDisplay();
127
- });
128
-
129
- updateStorageDisplay();
130
-
131
- // 全体の組み立て
132
- devToolsContainer.insertBefore(tabBar, devToolsContainer.firstChild);
133
- document.body.appendChild(devToolsContainer);
134
-
135
- // 開閉制御
136
- openButton.addEventListener('click', () => {
137
- devToolsContainer.style.display = 'flex';
138
- contentAreas['Console'].style.display = 'block';
139
- tabs[0].classList.add('active');
140
- });
141
  });
 
1
  // dev-tools.js
2
  document.addEventListener('DOMContentLoaded', () => {
3
+ // スタイル定義
4
+ const style = document.createElement('style');
5
+ style.textContent = `
6
+ :root {
7
+ --devtools-blue: #1a1c2c;
8
+ --neon-blue: #00f3ff;
9
+ --dark-layer: rgba(0, 0, 0, 0.9);
10
+ }
11
+
12
+ .devtools-btn {
13
+ position: fixed;
14
+ bottom: 20px;
15
+ right: 20px;
16
+ background: var(--devtools-blue);
17
+ color: var(--neon-blue);
18
+ border: 2px solid var(--neon-blue);
19
+ padding: 10px 20px;
20
+ cursor: pointer;
21
+ border-radius: 5px;
22
+ font-family: 'Courier New', monospace;
23
+ z-index: 10000;
24
+ transition: all 0.3s;
25
+ }
26
+
27
+ .devtools-btn:hover {
28
+ box-shadow: 0 0 15px var(--neon-blue);
29
+ }
30
+
31
+ .devtools-panel {
32
+ position: fixed;
33
+ bottom: 0;
34
+ right: 0;
35
+ width: 100%;
36
+ height: 60vh;
37
+ background: var(--dark-layer);
38
+ border-top: 3px solid var(--neon-blue);
39
+ color: white;
40
+ font-family: 'Courier New', monospace;
41
+ display: none;
42
+ z-index: 9999;
43
+ }
44
+
45
+ .tabs {
46
+ display: flex;
47
+ background: var(--devtools-blue);
48
+ border-bottom: 1px solid var(--neon-blue);
49
+ }
50
+
51
+ .tab {
52
+ padding: 10px 20px;
53
+ cursor: pointer;
54
+ border-right: 1px solid var(--neon-blue);
55
+ }
56
+
57
+ .tab.active {
58
+ background: var(--neon-blue);
59
+ color: var(--devtools-blue);
60
+ }
61
+
62
+ .panel-content {
63
+ padding: 15px;
64
+ overflow-y: auto;
65
+ height: calc(100% - 50px);
66
+ }
67
+
68
+ .dom-node {
69
+ margin-left: 15px;
70
+ cursor: pointer;
71
+ }
72
+
73
+ .dom-node::before {
74
+ content: '▶';
75
+ margin-right: 5px;
76
+ transition: transform 0.2s;
77
+ }
78
+
79
+ .dom-node.expanded::before {
80
+ transform: rotate(90deg);
81
+ }
82
+
83
+ .console-input {
84
+ width: 100%;
85
+ background: transparent;
86
+ border: 1px solid var(--neon-blue);
87
+ color: white;
88
+ padding: 5px;
89
+ margin-top: 10px;
90
+ }
91
+
92
+ .console-log {
93
+ white-space: pre-wrap;
94
+ color: var(--neon-blue);
95
+ }
96
+ `;
97
+ document.head.appendChild(style);
98
+
99
+ // 開発者ツール起動ボタン
100
+ const openBtn = document.createElement('button');
101
+ openBtn.className = 'devtools-btn';
102
+ openBtn.textContent = '🛠 Open DevTools';
103
+ document.body.appendChild(openBtn);
104
+
105
+ // 開発者ツールパネル
106
+ const panel = document.createElement('div');
107
+ panel.className = 'devtools-panel';
108
+
109
+ // タブインターフェイス
110
+ const tabs = ['Console', 'Elements', 'Styles'].map(name => {
111
+ const tab = document.createElement('div');
112
+ tab.className = 'tab';
113
+ tab.textContent = name;
114
+ return tab;
115
  });
116
+
117
+ const tabContent = document.createElement('div');
118
+ tabContent.className = 'panel-content';
119
+
120
+ // コンソールタブ
121
+ const consoleInput = document.createElement('input');
122
+ consoleInput.className = 'console-input';
123
+ consoleInput.placeholder = 'Enter JavaScript...';
124
+
125
+ const consoleLog = document.createElement('pre');
126
+ consoleLog.className = 'console-log';
127
+
128
+ // ログキャプチャ
129
+ const originalConsoleLog = console.log;
130
+ console.log = (...args) => {
131
+ originalConsoleLog(...args);
132
+ consoleLog.textContent += args.join(' ') + '\n';
133
+ };
134
+
135
+ // DOMインスペクタ
136
+ function createDOMTree(node, depth = 0) {
137
+ const element = document.createElement('div');
138
+ element.className = 'dom-node';
139
+ element.textContent = node.nodeName.toLowerCase();
140
+
141
+ if (node.childNodes.length > 0) {
142
+ node.childNodes.forEach(child => {
143
+ if (child.nodeType === Node.ELEMENT_NODE) {
144
+ element.appendChild(createDOMTree(child, depth + 1));
145
+ }
146
+ });
147
+ }
148
+
149
+ element.addEventListener('click', (e) => {
150
+ e.stopPropagation();
151
+ element.classList.toggle('expanded');
152
+ });
153
+
154
+ return element;
155
  }
156
+
157
+ // タブ切り替え
158
+ tabs.forEach((tab, index) => {
159
+ tab.addEventListener('click', () => {
160
+ tabs.forEach(t => t.classList.remove('active'));
161
+ tab.classList.add('active');
162
+
163
+ tabContent.innerHTML = '';
164
+ switch(index) {
165
+ case 0:
166
+ tabContent.appendChild(consoleLog);
167
+ tabContent.appendChild(consoleInput);
168
+ break;
169
+ case 1:
170
+ tabContent.appendChild(createDOMTree(document.documentElement));
171
+ break;
172
+ }
173
+ });
174
+ });
175
+
176
+ // パネル構成
177
+ panel.appendChild(tabs.reduce((container, tab) => {
178
+ container.appendChild(tab);
179
+ return container;
180
+ }, document.createElement('div')));
181
+ panel.appendChild(tabContent);
182
+
183
+ // イベントハンドラ
184
+ openBtn.addEventListener('click', () => {
185
+ panel.style.display = 'block';
186
+ tabs[0].click();
187
  });
188
+
189
+ consoleInput.addEventListener('keypress', (e) => {
190
+ if (e.key === 'Enter') {
191
+ try {
192
+ eval(e.target.value);
193
+ } catch (err) {
194
+ console.log('Error:', err);
195
+ }
196
+ e.target.value = '';
197
+ }
198
+ });
199
+
200
+ document.body.appendChild(panel);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  });