MediaWiki:Gadget-clock.js

来自灵魂之流资料站
Flandre留言 | 贡献2024年8月20日 (二) 10:44的版本

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
(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;
        }
    }
    
    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);
    }

    // Add the clock element to the page
    document.addEventListener('DOMContentLoaded', event => {
    	console.log('dom loaded')
    	console.log(event)
    	createClockElement()
	});
    // createClockElement()
})();