MediaWiki:Gadget-clock.js:修订间差异
无编辑摘要 |
无编辑摘要 |
||
第21行: | 第21行: | ||
// Add the clock element to the page | // Add the clock element to the page | ||
document.addEventListener('DOMContentLoaded', function () { | document.addEventListener('DOMContentLoaded', function () { | ||
console.log('page loaded') | |||
var clockDiv = document.createElement('div'); | var clockDiv = document.createElement('div'); | ||
clockDiv.id = 'clock'; | clockDiv.id = 'clock'; |
2024年8月20日 (二) 09:56的版本
(function () { console.log('Common.js loaded'); function updateClock() { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); // Format time as HH:MM:SS hours = hours < 10 ? '0' + hours : hours; minutes = minutes < 10 ? '0' + minutes : minutes; seconds = seconds < 10 ? '0' + seconds : seconds; // Update the clock element var clockElement = document.getElementById('clock'); if (clockElement) { clockElement.innerHTML = hours + ':' + minutes + ':' + seconds; } } // Add the clock element to the page document.addEventListener('DOMContentLoaded', function () { console.log('page loaded') var clockDiv = document.createElement('div'); clockDiv.id = 'clock'; clockDiv.style.fontSize = '2em'; clockDiv.style.textAlign = 'center'; clockDiv.style.marginTop = '20px'; document.body.insertBefore(clockDiv, document.body.firstChild); // Start the clock updateClock(); setInterval(updateClock, 1000); }); })();