<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>高度なコード比較サイト</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
width: 90%;
max-width: 900px;
margin: 20px auto;
background: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
border-radius: 5px;
}
h1 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.code-input {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
gap: 10px;
}
textarea {
width: 48%;
height: 300px;
font-family: monospace;
font-size: 14px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
resize: none;
background-color: #f9f9f9;
}
.buttons {
display: flex;
justify-content: center;
gap: 10px;
}
button {
padding: 10px 20px;
background: #007BFF;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background: #0056b3;
}
#result {
white-space: pre-wrap;
font-family: monospace;
background-color: #f8f9fa;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
max-height: 300px;
overflow-y: auto;
}
.highlight {
background-color: #ffcccc;
font-weight: bold;
color: #d9534f;
}
.line {
border-left: 4px solid #ccc;
padding-left: 10px;
margin: 5px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>高度なコード比較ツール</h1>
<div class="code-input">
<textarea id="code1" placeholder="コード1を入力..."></textarea>
<textarea id="code2" placeholder="コード2を入力..."></textarea>
</div>
<div class="buttons">
<button onclick="compareCodes()">比較する</button>
<button onclick="clearFields()">クリア</button>
</div>
<h3>比較結果</h3>
<div id="result">
<!-- 結果表示エリア -->
</div>
</div>
<script>
function compareCodes() {
const code1 = document.getElementById('code1').value.split('\n');
const code2 = document.getElementById('code2').value.split('\n');
const resultContainer = document.getElementById('result');
resultContainer.innerHTML = '';
const maxLength = Math.max(code1.length, code2.length);
for (let i = 0; i < maxLength; i++) {
const line1 = code1[i] || '';
const line2 = code2[i] || '';
const lineClass = line1 !== line2 ? 'highlight' : '';
resultContainer.innerHTML += `
<div class="line">
<strong>行 ${i + 1}:</strong>
<span class="${lineClass}">コード1: "${line1}"</span> |
<span class="${lineClass}">コード2: "${line2}"</span>
</div>`;
}
if (!resultContainer.innerHTML.trim()) {
resultContainer.innerHTML = '<div>コードに違いはありません。</div>';
}
}
function clearFields() {
document.getElementById('code1').value = '';
document.getElementById('code2').value = '';
document.getElementById('result').innerHTML = '';
}
</script>
</body>
</html>