MediaWiki:Gadget-clock.js:修订间差异
创建页面,内容为“(function () { 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.…” |
无编辑摘要 |
||
(未显示同一用户的6个中间版本) | |||
第1行: | 第1行: | ||
(function () { | (function () { | ||
console.log(mw.config); | |||
if(typeof mw.config === 'object') { | |||
console.log(JSON.stringify(mw.config)) | |||
} | |||
function updateClock() { | function updateClock() { | ||
var now = new Date(); | var now = new Date(); | ||
第17行: | 第21行: | ||
} | } | ||
} | } | ||
function createClockElement() { | |||
console.log('page loaded') | |||
var clockDiv = document.createElement('div'); | var clockDiv = document.createElement('div'); | ||
clockDiv.id = 'clock'; | clockDiv.id = 'clock'; | ||
第30行: | 第34行: | ||
updateClock(); | updateClock(); | ||
setInterval(updateClock, 1000); | setInterval(updateClock, 1000); | ||
}); | } | ||
if (document.readyState === "loading") { | |||
// 此时加载尚未完成 | |||
// Add the clock element to the page | |||
console.log('DOMContentLoaded 尚未触发') | |||
document.addEventListener('DOMContentLoaded', event => { | |||
console.log('dom loaded') | |||
console.log(event) | |||
createClockElement() | |||
}); | |||
} else { | |||
// `DOMContentLoaded` 已经被触发 | |||
console.log('DOMContentLoaded 已经被触发') | |||
createClockElement() | |||
} | |||
})(); | })(); |
2024年8月20日 (二) 16:53的最新版本
(function () { console.log(mw.config); if(typeof mw.config === 'object') { console.log(JSON.stringify(mw.config)) } 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; } } function createClockElement() { 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); } if (document.readyState === "loading") { // 此时加载尚未完成 // Add the clock element to the page console.log('DOMContentLoaded 尚未触发') document.addEventListener('DOMContentLoaded', event => { console.log('dom loaded') console.log(event) createClockElement() }); } else { // `DOMContentLoaded` 已经被触发 console.log('DOMContentLoaded 已经被触发') createClockElement() } })();