File size: 5,355 Bytes
e7e019f cd1febc e7e019f cd1febc e7e019f cd1febc e7e019f cd1febc e7e019f |
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 |
// dev-tools.js
document.addEventListener('DOMContentLoaded', () => {
// スタイル定義
const style = document.createElement('style');
style.textContent = `
:root {
--devtools-blue: #1a1c2c;
--neon-blue: #00f3ff;
--dark-layer: rgba(0, 0, 0, 0.9);
}
.devtools-btn {
position: fixed;
bottom: 20px;
right: 20px;
background: var(--devtools-blue);
color: var(--neon-blue);
border: 2px solid var(--neon-blue);
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
font-family: 'Courier New', monospace;
z-index: 10000;
transition: all 0.3s;
}
.devtools-btn:hover {
box-shadow: 0 0 15px var(--neon-blue);
}
.devtools-panel {
position: fixed;
bottom: 0;
right: 0;
width: 100%;
height: 60vh;
background: var(--dark-layer);
border-top: 3px solid var(--neon-blue);
color: white;
font-family: 'Courier New', monospace;
display: none;
z-index: 9999;
}
.tabs {
display: flex;
background: var(--devtools-blue);
border-bottom: 1px solid var(--neon-blue);
}
.tab {
padding: 10px 20px;
cursor: pointer;
border-right: 1px solid var(--neon-blue);
}
.tab.active {
background: var(--neon-blue);
color: var(--devtools-blue);
}
.panel-content {
padding: 15px;
overflow-y: auto;
height: calc(100% - 50px);
}
.dom-node {
margin-left: 15px;
cursor: pointer;
}
.dom-node::before {
content: '▶';
margin-right: 5px;
transition: transform 0.2s;
}
.dom-node.expanded::before {
transform: rotate(90deg);
}
.console-input {
width: 100%;
background: transparent;
border: 1px solid var(--neon-blue);
color: white;
padding: 5px;
margin-top: 10px;
}
.console-log {
white-space: pre-wrap;
color: var(--neon-blue);
}
`;
document.head.appendChild(style);
// 開発者ツール起動ボタン
const openBtn = document.createElement('button');
openBtn.className = 'devtools-btn';
openBtn.textContent = '🛠 Open DevTools';
document.body.appendChild(openBtn);
// 開発者ツールパネル
const panel = document.createElement('div');
panel.className = 'devtools-panel';
// タブインターフェイス
const tabs = ['Console', 'Elements', 'Styles'].map(name => {
const tab = document.createElement('div');
tab.className = 'tab';
tab.textContent = name;
return tab;
});
const tabContent = document.createElement('div');
tabContent.className = 'panel-content';
// コンソールタブ
const consoleInput = document.createElement('input');
consoleInput.className = 'console-input';
consoleInput.placeholder = 'Enter JavaScript...';
const consoleLog = document.createElement('pre');
consoleLog.className = 'console-log';
// ログキャプチャ
const originalConsoleLog = console.log;
console.log = (...args) => {
originalConsoleLog(...args);
consoleLog.textContent += args.join(' ') + '\n';
};
// DOMインスペクタ
function createDOMTree(node, depth = 0) {
const element = document.createElement('div');
element.className = 'dom-node';
element.textContent = node.nodeName.toLowerCase();
if (node.childNodes.length > 0) {
node.childNodes.forEach(child => {
if (child.nodeType === Node.ELEMENT_NODE) {
element.appendChild(createDOMTree(child, depth + 1));
}
});
}
element.addEventListener('click', (e) => {
e.stopPropagation();
element.classList.toggle('expanded');
});
return element;
}
// タブ切り替え
tabs.forEach((tab, index) => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
tabContent.innerHTML = '';
switch(index) {
case 0:
tabContent.appendChild(consoleLog);
tabContent.appendChild(consoleInput);
break;
case 1:
tabContent.appendChild(createDOMTree(document.documentElement));
break;
}
});
});
// パネル構成
panel.appendChild(tabs.reduce((container, tab) => {
container.appendChild(tab);
return container;
}, document.createElement('div')));
panel.appendChild(tabContent);
// イベントハンドラ
openBtn.addEventListener('click', () => {
panel.style.display = 'block';
tabs[0].click();
});
consoleInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
try {
eval(e.target.value);
} catch (err) {
console.log('Error:', err);
}
e.target.value = '';
}
});
document.body.appendChild(panel);
}); |