Create dev-tools.js
Browse files- dev-tools.js +141 -0
dev-tools.js
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
});
|