mini clock 2025figuccio

clock 2025 dragabile

Ekde 2025/03/30. Vidu La ĝisdata versio.

// ==UserScript==
// @name         mini clock 2025figuccio
// @namespace    https://greasyforks.org/users/237458
// @description  clock 2025 dragabile
// @version      2.2
// @match        *://*/*
// @noframes
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @icon         data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
// @require      http://code.jquery.com/jquery-latest.js
// @require      https://code.jquery.com/ui/1.13.2/jquery-ui.js
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';
    // Funzione per salvare la posizione nel local storage
    function savePosition(left, top) {
        GM_setValue('clockPosition', JSON.stringify({ left: left, top: top }));
    }

    // Funzione per recuperare la posizione dal local storage
    function loadPosition() {
        let position = GM_getValue('clockPosition');
        return position ? JSON.parse(position) : { left: '900px', top: '0px' };
    }

    // Creazione dell'elemento dell'orologio
    var clock = document.createElement('div');
    clock.style.position = 'fixed';
    clock.style.fontSize = '16px';
    clock.style.width ='90px';
    clock.style.cursor = 'pointer';
    clock.style.backgroundColor = '#181818';
    clock.style.color = 'red';
    clock.style.padding = '1px 7px';
    clock.style.border ='2px solid green';
    clock.style.borderRadius = '5px';
    clock.style.zIndex = '999999';
    document.body.appendChild(clock);

    // Impostazione della posizione iniziale
    let initialPosition = loadPosition();
    clock.style.left = initialPosition.left;
    clock.style.top = initialPosition.top;

    // Funzione per aggiornare l'orologio
    function updateClock() {
        var now = new Date();
        var hours = String(now.getHours()).padStart(2, '0');
        var minutes = String(now.getMinutes()).padStart(2, '0');
        var seconds = String(now.getSeconds()).padStart(2, '0');
        var milliseconds = String(now.getMilliseconds()).padStart(3, '0');
        clock.textContent = `${hours}:${minutes}:${seconds}:${milliseconds}`;
    }

    // Aggiornamento dell'orologio ogni 90 millisecondi
    setInterval(updateClock, 90);

    // Mostrare la data al passaggio del mouse
    clock.addEventListener('mouseenter', function() {
        let currentDate = new Date();
        clock.setAttribute('title', currentDate.toLocaleDateString('it', { day: '2-digit', month: 'long', weekday: 'long', year: 'numeric' }));
    });

    // Funzioni per rendere l'orologio trascinabile con limiti
    clock.addEventListener('mousedown', function(e) {
        var offsetX = e.clientX - parseInt(clock.style.left);
        var offsetY = e.clientY - parseInt(clock.style.top);

        function mouseMoveHandler(e) {
            var newLeft = e.clientX - offsetX;
            var newTop = e.clientY - offsetY;

            // Limiti per il trascinamento
            var minLeft = 0;
            var maxLeft = window.innerWidth - clock.offsetWidth;
            var minTop = 0;
            var maxTop = window.innerHeight - clock.offsetHeight;

            // Applicazione dei limiti
            if (newLeft < minLeft) newLeft = minLeft;
            if (newLeft > maxLeft) newLeft = maxLeft;
            if (newTop < minTop) newTop = minTop;
            if (newTop > maxTop) newTop = maxTop;

            clock.style.left = newLeft + 'px';
            clock.style.top = newTop + 'px';
            savePosition(clock.style.left, clock.style.top);
        }

        function reset() {
            document.removeEventListener('mousemove', mouseMoveHandler);
            document.removeEventListener('mouseup', reset);
        }

        document.addEventListener('mousemove', mouseMoveHandler);
        document.addEventListener('mouseup', reset);
    });
     // Funzioni per mostrare/nascondere l'orologio
    function toggleClockVisibility() {
        if (clock.style.display === 'none') {
            clock.style.display = 'block';
        } else {
            clock.style.display = 'none';
        }
    }

    // Aggiungi comando al menu di Greasemonkey/Tampermonkey
    GM_registerMenuCommand('Mostra/Nascondi Orologio', toggleClockVisibility);
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。