Update dev-tools.js
Browse files- dev-tools.js +195 -135
dev-tools.js
CHANGED
@@ -1,141 +1,201 @@
|
|
1 |
// dev-tools.js
|
2 |
document.addEventListener('DOMContentLoaded', () => {
|
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 |
-
<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 |
});
|