Here's a simple clone of the core functions of csTimer in a single HTML file. This implementation includes the essential features like timing, scrambling, basic statistics, and session management.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>csTimer Clone</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
background-color: #f0f0f0;
height: 100vh;
}
#container {
width: 90%;
max-width: 800px;
margin: 20px auto;
display: flex;
flex-direction: column;
align-items: center;
}
#scramble-panel {
width: 100%;
padding: 15px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
margin-bottom: 20px;
text-align: center;
font-size: 18px;
}
#scramble-type {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
#scramble-type select {
padding: 5px;
margin-right: 10px;
}
#scramble-text {
min-height: 40px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
}
#timer {
width: 100%;
height: 150px;
display: flex;
align-items: center;
justify-content: center;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
font-size: 60px;
font-weight: bold;
cursor: pointer;
user-select: none;
margin-bottom: 20px;
position: relative;
}
#timer.ready {
background-color: #4CAF50;
color: white;
}
#timer.running {
background-color: #f44336;
color: white;
}
#timer.inspection {
background-color: #2196F3;
color: white;
}
#times-panel {
width: 100%;
display: flex;
flex-direction: column;
}
#stats {
padding: 15px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
#times-list {
height: 200px;
overflow-y: auto;
padding: 15px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.time-item {
padding: 5px;
border-bottom: 1px solid #eee;
display: flex;
justify-content: space-between;
}
.time-item:hover {
background-color: #f5f5f5;
}
.solve-time {
font-weight: bold;
}
.tools {
display: flex;
justify-content: space-between;
width: 100%;
margin-bottom: 20px;
}
button {
padding: 8px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
button:hover {
background-color: #45a049;
}
#settings-panel {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
z-index: 10;
width: 300px;
}
.setting-item {
margin-bottom: 15px;
}
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
z-index: 5;
}
</style>
</head>
<body>
<div id="container">
<div id="scramble-panel">
<div id="scramble-type">
<select id="puzzle-type">
<option value="333">3x3x3</option>
<option value="222">2x2x2</option>
<option value="444">4x4x4</option>
<option value="555">5x5x5</option>
<option value="pyram">Pyraminx</option>
<option value="skewb">Skewb</option>
<option value="sq1">Square-1</option>
<option value="mega">Megaminx</option>
</select>
<button id="new-scramble">New Scramble</button>
</div>
<div id="scramble-text">Loading scramble...</div>
</div>
<div id="timer">0.000</div>
<div class="tools">
<button id="settings-btn">Settings</button>
<button id="reset-session">Reset Session</button>
<button id="export-times">Export Times</button>
</div>
<div id="times-panel">
<div id="stats">
<div>Session: <span id="session-name">Session 1</span></div>
<div>Solves: <span id="solve-count">0</span></div>
<div>Average: <span id="average">-</span></div>
<div>Best: <span id="best-time">-</span></div>
<div>Ao5: <span id="ao5">-</span></div>
<div>Ao12: <span id="ao12">-</span></div>
</div>
<div id="times-list"></div>
</div>
</div>
<div class="overlay" id="overlay"></div>
<div id="settings-panel">
<h3>Settings</h3>
<div class="setting-item">
<label for="inspection">WCA Inspection:</label>
<select id="inspection">
<option value="none">None</option>
<option value="wca">15s WCA Inspection</option>
</select>
</div>
<div class="setting-item">
<label for="timer-update">Timer Update:</label>
<select id="timer-update">
<option value="0.001">0.001s</option>
<option value="0.01">0.01s</option>
<option value="0.1">0.1s</option>
</select>
</div>
<div class="setting-item">
<label for="input-method">Input Method:</label>
<select id="input-method">
<option value="timer">Timer</option>
<option value="typing">Manual Input</option>
</select>
</div>
<button id="close-settings">Close</button>
</div>
<script>
// DOM Elements
const timerElement = document.getElementById('timer');
const scrambleTextElement = document.getElementById('scramble-text');
const puzzleTypeElement = document.getElementById('puzzle-type');
const newScrambleButton = document.getElementById('new-scramble');
const timesListElement = document.getElementById('times-list');
const resetSessionButton = document.getElementById('reset-session');
const exportTimesButton = document.getElementById('export-times');
const settingsButton = document.getElementById('settings-btn');
const closeSettingsButton = document.getElementById('close-settings');
const overlayElement = document.getElementById('overlay');
const settingsPanel = document.getElementById('settings-panel');
const inspectionSetting = document.getElementById('inspection');
const timerUpdateSetting = document.getElementById('timer-update');
const inputMethodSetting = document.getElementById('input-method');
// Statistics elements
const solveCountElement = document.getElementById('solve-count');
const averageElement = document.getElementById('average');
const bestTimeElement = document.getElementById('best-time');
const ao5Element = document.getElementById('ao5');
const ao12Element = document.getElementById('ao12');
// Timer state
let timerRunning = false;
let timerReady = false;
let inspectionRunning = false;
let startTime = 0;
let elapsedTime = 0;
let timerInterval;
let inspectionTime = 15;
let inspectionInterval;
let useInspection = false;
let timerUpdateInterval = 10; // milliseconds (0.01s)
let inputMethod = 'timer';
// Session data
let times = [];
let scrambles = [];
let currentScramble = '';
// Scramble functions
function generateScramble(puzzleType) {
let scramble = '';
const moves = {
'333': ['U', 'D', 'L', 'R', 'F', 'B'],
'222': ['U', 'R', 'F'],
'444': ['U', 'D', 'L', 'R', 'F', 'B', 'Uw', 'Rw', 'Fw'],
'555': ['U', 'D', 'L', 'R', 'F', 'B', 'Uw', 'Dw', 'Lw', 'Rw', 'Fw', 'Bw'],
'pyram': ['U', 'L', 'R', 'B', 'u', 'l', 'r', 'b'],
'skewb': ['U', 'L', 'R', 'B'],
'sq1': ['(0,1)', '(1,0)', '(1,-1)', '(0,-1)', '(-1,0)', '(-1,1)', '/'],
'mega': ['R++', 'R--', 'D++', 'D--', 'U']
};
const modifiers = ["", "'", "2"];
const length = puzzleType === '222' ? 10 : puzzleType === '333' ? 20 : 25;
if (puzzleType === 'sq1') {
for (let i = 0; i < 15; i++) {
scramble += moves[puzzleType][Math.floor(Math.random() * moves[puzzleType].length)] + ' ';
}
} else if (puzzleType === 'mega') {
scramble = "R++ D++ R++ D++ R++ D++ R++ D++ U\nR++ D++ R++ D++ R++ D++ R++ D++ U\nR++ D++ R++ D++ R++ D++ R++ D++ U\nR++ D++ R++ D++ R++ D++ R++ D++ U\nR++ D++ R++ D++ R++ D++ R++ D++ U\nR++ D++ R++ D++ R++ D++ R++ D++ U";
} else {
let lastMove = '';
let lastAxis = '';
for (let i = 0; i < length; i++) {
let move;
let axis;
do {
move = moves[puzzleType][Math.floor(Math.random() * moves[puzzleType].length)];
axis = move.charAt(0);
// Ensure we don't get moves on the same axis consecutively
if (axis === 'u') axis = 'U';
if (axis === 'l') axis = 'L';
if (axis === 'r') axis = 'R';
if (axis === 'b') axis = 'B';
} while (axis === lastAxis);
const modifier = modifiers[Math.floor(Math.random() * modifiers.length)];
scramble += move + modifier + ' ';
lastMove = move;
lastAxis = axis;
}
}
return scramble.trim();
}
function updateScramble() {
const puzzleType = puzzleTypeElement.value;
currentScramble = generateScramble(puzzleType);
scrambleTextElement.textContent = currentScramble;
}
// Timer functions
function formatTime(timeInMs) {
if (timeInMs === 0) return '0.000';
const ms = timeInMs % 1000;
const sec = Math.floor(timeInMs / 1000) % 60;
const min = Math.floor(timeInMs / 60000);
if (min > 0) {
return `${min}:${sec.toString().padStart(2, '0')}.${ms.toString().padStart(3, '0')}`;
} else {
return `${sec}.${ms.toString().padStart(3, '0')}`;
}
}
function startInspection() {
inspectionRunning = true;
timerElement.classList.add('inspection');
timerElement.textContent = inspectionTime;
inspectionInterval = setInterval(() => {
inspectionTime--;
timerElement.textContent = inspectionTime;
if (inspectionTime <= 0) {
clearInterval(inspectionInterval);
timerElement.textContent = '+2';
// After 2 more seconds, DNF
setTimeout(() => {
if (inspectionRunning) {
timerElement.textContent = 'DNF';
inspectionRunning = false;
}
}, 2000);
}
}, 1000);
}
function stopInspection() {
if (inspectionRunning) {
clearInterval(inspectionInterval);
inspectionRunning = false;
inspectionTime = 15;
timerElement.classList.remove('inspection');
}
}
function startTimer() {
timerRunning = true;
startTime = Date.now() - elapsedTime;
timerElement.classList.add('running');
timerInterval = setInterval(() => {
elapsedTime = Date.now() - startTime;
timerElement.textContent = formatTime(elapsedTime);
}, timerUpdateInterval);
}
function stopTimer() {
if (timerRunning) {
clearInterval(timerInterval);
timerRunning = false;
timerElement.classList.remove('running');
// Add time to list
addTime(elapsedTime);
// Generate new scramble
updateScramble();
}
}
function resetTimer() {
stopTimer();
elapsedTime = 0;
timerElement.textContent = formatTime(elapsedTime);
}
// Session functions
function addTime(timeInMs) {
times.push(timeInMs);
scrambles.push(currentScramble);
// Add to UI
const timeItem = document.createElement('div');
timeItem.className = 'time-item';
const index = times.length;
const timeFormatted = formatTime(timeInMs);
timeItem.innerHTML = `
<span>${index}. </span>
<span class="solve-time">${timeFormatted}</span>
`;
timesListElement.insertBefore(timeItem, timesListElement.firstChild);
// Update statistics
updateStats();
}
function updateStats() {
solveCountElement.textContent = times.length;
if (times.length > 0) {
// Calculate average
const sum = times.reduce((a, b) => a + b, 0);
const avg = sum / times.length;
averageElement.textContent = formatTime(avg);
// Find best time
const best = Math.min(...times);
bestTimeElement.textContent = formatTime(best);
// Calculate ao5
if (times.length >= 5) {
const ao5 = calculateAverage(times.slice(-5));
ao5Element.textContent = formatTime(ao5);
} else {
ao5Element.textContent = '-';
}
// Calculate ao12
if (times.length >= 12) {
const ao12 = calculateAverage(times.slice(-12));
ao12Element.textContent = formatTime(ao12);
} else {
ao12Element.textContent = '-';
}
} else {
averageElement.textContent = '-';
bestTimeElement.textContent = '-';
ao5Element.textContent = '-';
ao12Element.textContent = '-';
}
}
function calculateAverage(timeArray) {
if (timeArray.length <= 2) return 0;
const sortedTimes = [...timeArray].sort((a, b) => a - b);
// Remove best and worst
sortedTimes.shift();
sortedTimes.pop();
// Calculate average of remaining times
const sum = sortedTimes.reduce((a, b) => a + b, 0);
return sum / sortedTimes.length;
}
function resetSession() {
times = [];
scrambles = [];
timesListElement.innerHTML = '';
updateStats();
updateScramble();
}
function exportTimes() {
let exportText = 'csTimer Clone Export\n\n';
exportText += `Session: Session 1\n`;
exportText += `Date: ${new Date().toLocaleString()}\n\n`;
exportText += 'Times:\n';
for (let i = 0; i < times.length; i++) {
exportText += `${i+1}. ${formatTime(times[i])} - ${scrambles[i]}\n`;
}
if (times.length > 0) {
exportText += `\nStatistics:\n`;
exportText += `Number of solves: ${times.length}\n`;
const sum = times.reduce((a, b) => a + b, 0);
const avg = sum / times.length;
exportText += `Average: ${formatTime(avg)}\n`;
const best = Math.min(...times);
exportText += `Best time: ${formatTime(best)}\n`;
if (times.length >= 5) {
const ao5 = calculateAverage(times.slice(-5));
exportText += `Current Ao5: ${formatTime(ao5)}\n`;
}
if (times.length >= 12) {
const ao12 = calculateAverage(times.slice(-12));
exportText += `Current Ao12: ${formatTime(ao12)}\n`;
}
}
// Create temporary textarea to copy to clipboard
const textarea = document.createElement('textarea');
textarea.value = exportText;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
alert('Times exported and copied to clipboard!');
}
// Event listeners
document.addEventListener('keydown', (e) => {
if (e.code === 'Space') {
e.preventDefault();
if (inspectionRunning) {
stopInspection();
startTimer();
} else if (!timerRunning && !timerReady) {
timerReady = true;
timerElement.classList.add('ready');
}
}
});
document.addEventListener('keyup', (e) => {
if (e.code === 'Space') {
if (timerReady && !timerRunning) {
timerElement.classList.remove('ready');
timerReady = false;
if (useInspection && !inspectionRunning) {
startInspection();
} else {
startTimer();
}
} else if (timerRunning) {
stopTimer();
}
}
});
newScrambleButton.addEventListener('click', updateScramble);
resetSessionButton.addEventListener('click', resetSession);
exportTimesButton.addEventListener('click', exportTimes);
puzzleTypeElement.addEventListener('change', updateScramble);
// Settings panel
settingsButton.addEventListener('click', () => {
settingsPanel.style.display = 'block';
overlayElement.style.display = 'block';
});
closeSettingsButton.addEventListener('click', () => {
settingsPanel.style.display = 'none';
overlayElement.style.display = 'none';
});
inspectionSetting.addEventListener('change', () => {
useInspection = inspectionSetting.value === 'wca';
});
timerUpdateSetting.addEventListener('change', () => {
timerUpdateInterval = parseFloat(timerUpdateSetting.value) * 1000;
});
inputMethodSetting.addEventListener('change', () => {
inputMethod = inputMethodSetting.value;
if (inputMethod === 'typing') {
timerElement.textContent = 'Click to enter time';
timerElement.addEventListener('click', () => {
if (inputMethod === 'typing' && !timerRunning) {
const timeInput = prompt('Enter time in seconds (e.g., 12.345):');
if (timeInput !== null && timeInput !== '') {
const timeInSeconds = parseFloat(timeInput);
if (!isNaN(timeInSeconds)) {
const timeInMs = timeInSeconds * 1000;
timerElement.textContent = formatTime(timeInMs);
addTime(timeInMs);
updateScramble();
}
}
}
});
} else {
timerElement.textContent = '0.000';
}
});
// Initialize
updateScramble();
</script>
</body>
</html>
This implementation captures the essential functionality of csTimer while keeping everything in a single HTML file. It doesn't include some of the more advanced features like smart cube integration, draw scrambles, solve helpers, or multiple sessions, but provides a solid foundation for a speedcubing timer.