Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .jules/bolt.md
Empty file.
45 changes: 27 additions & 18 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -481,28 +481,37 @@ <h1>🌟 人生明燈</h1>
}

// 時間工具
// Performance Optimization: Cache Intl.DateTimeFormat instances (~25-100x faster than toLocaleString)
const timeFormatter = new Intl.DateTimeFormat('zh-TW', { hour: 'numeric', minute: 'numeric', second: 'numeric' });
const dateFormatter = new Intl.DateTimeFormat('zh-TW', { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' });
const tokyoFormatter = new Intl.DateTimeFormat('ja-JP', { timeZone: 'Asia/Tokyo', hour: 'numeric', minute: 'numeric', second: 'numeric' });
const nyFormatter = new Intl.DateTimeFormat('en-US', { timeZone: 'America/New_York', hour: 'numeric', minute: 'numeric', second: 'numeric' });
const londonFormatter = new Intl.DateTimeFormat('en-GB', { timeZone: 'Europe/London', hour: 'numeric', minute: 'numeric', second: 'numeric' });

let cachedTimeDiv, cachedTimeZonesDiv;

function updateTime() {
const now = new Date();
const timeDiv = document.getElementById('currentTime');
const timeZonesDiv = document.getElementById('timeZones');
// Performance Optimization: Cache DOM references to avoid repeated lookups
if (!cachedTimeDiv) cachedTimeDiv = document.getElementById('currentTime');
if (!cachedTimeZonesDiv) cachedTimeZonesDiv = document.getElementById('timeZones');

timeDiv.innerHTML = `
<div class="temp">${now.toLocaleTimeString('zh-TW')}</div>
<div>${now.toLocaleDateString('zh-TW', {
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'long'
})}</div>
`;
if (cachedTimeDiv) {
cachedTimeDiv.innerHTML = `
<div class="temp">${timeFormatter.format(now)}</div>
<div>${dateFormatter.format(now)}</div>
`;
}

timeZonesDiv.innerHTML = `
<small>
東京: ${now.toLocaleTimeString('ja-JP', {timeZone: 'Asia/Tokyo'})}<br>
紐約: ${now.toLocaleTimeString('en-US', {timeZone: 'America/New_York'})}<br>
倫敦: ${now.toLocaleTimeString('en-GB', {timeZone: 'Europe/London'})}
</small>
`;
if (cachedTimeZonesDiv) {
cachedTimeZonesDiv.innerHTML = `
<small>
東京: ${tokyoFormatter.format(now)}<br>
紐約: ${nyFormatter.format(now)}<br>
倫敦: ${londonFormatter.format(now)}
</small>
`;
}
}

// 實用函數
Expand Down