Clock figuccio 12-24

clock ore ampm 24h al passaggio mouse

当前为 2025-03-27 提交的版本,查看 最新版本

// ==UserScript==
// @name           Clock figuccio 12-24
// @description    clock ore ampm 24h al passaggio mouse
// @version        0.4
// @match          *://*/*
// @noframes
// @author         figuccio
// @grant          GM_setValue
// @grant          GM_getValue
// @grant          GM_registerMenuCommand
// @license        MIT
// @icon           data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
// @namespace https://gf.qytechs.cn/users/237458
// ==/UserScript==
(function() {
    'use strict';
    //12h
function getCurrentTime() {
    const now = new Date();
    let hours = now.getHours();
    const minutes = now.getMinutes();
    const seconds = now.getSeconds();
    const milliseconds = now.getMilliseconds();
    const ampm = hours >= 12 ? 'PM' : 'AM';
    hours = hours % 12 || 12;
    return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}:${milliseconds.toString().padStart(3, '0')} ${ampm}`;
}

function updateClock24h() {
    const now = new Date();
    const time = now.toLocaleTimeString('it', { hour12: false });
    const ms = now.getMilliseconds();
    return `${time}:${ms}`;
}

function makeDraggable(element) {
    let offsetX = 0, offsetY = 0, mouseDown = false;

    element.addEventListener('mousedown', (e) => {
        mouseDown = true;
        offsetX = e.clientX - element.offsetLeft;
        offsetY = e.clientY - element.offsetTop;
    });

    document.addEventListener('mouseup', () => { mouseDown = false; });

    document.addEventListener('mousemove', (e) => {
        if (mouseDown) {
            let x = e.clientX - offsetX;
            let y = e.clientY - offsetY;

            // Limit movement within window
            x = Math.max(0, Math.min(window.innerWidth - element.offsetWidth, x));
            y = Math.max(0, Math.min(window.innerHeight - element.offsetHeight, y));

            element.style.left = `${x}px`;
            element.style.top = `${y}px`;

            // Save position to localStorage
             GM_setValue('clockPosition', JSON.stringify({ x, y }));
        }
    });
}

function createClock() {
    const clock = document.createElement('div');
    clock.id = 'clock';
    clock.style.position = 'fixed';
    clock.style.top = '0px';
    clock.style.left = '0px';
    clock.style.padding = '5px';
    clock.style.background = 'black';
    clock.style.color = 'lime';
    clock.style.border = '2px solid gold';
    clock.style.borderRadius = '5px';
    clock.style.fontFamily = 'Arial, sans-serif';
    clock.style.fontSize = '14px';
    clock.style.width='109px';
    clock.style.textAlign = 'center';
    clock.style.zIndex = '999999';
    document.body.appendChild(clock);
    makeDraggable(clock);

    // Load position from localStorage
    const savedPosition = JSON.parse(GM_getValue('clockPosition', JSON.stringify({ x: 0, y: 0 })));
    if (savedPosition) {
        clock.style.left = `${savedPosition.x}px`;
        clock.style.top = `${savedPosition.y}px`;
    }

    let is24h = false;
    GM_registerMenuCommand("Toggle 12h/24h", () => { is24h = !is24h; });
clock.addEventListener('mouseenter',() => {
    is24h = !is24h;
    // You might also want to update the clock display format here
    console.log(`Clock format toggled. Current format: ${is24h ? '24h' : '12h'}`);
});
    setInterval(() => {
        clock.textContent = is24h ? updateClock24h() : getCurrentTime();
    }, 70);
}

createClock();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址