Display Ora corrente con Milliseconds and AM/PM

Visualizza l'ora corrente in millisecondi e nel formato AM/PM (2024)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Display Ora corrente con Milliseconds and AM/PM
// @namespace    https://greasyfork.org/users/237458
// @version      0.3
// @description  Visualizza l'ora corrente in millisecondi e nel formato AM/PM (2024)
// @author       figuccio
// @match        https://*/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @require      http://code.jquery.com/jquery-latest.js
// @require      https://code.jquery.com/ui/1.13.2/jquery-ui.js
// @icon         data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
// @noframes
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';
    var $ = window.jQuery;
    let use24HourFormat = false; // Variabile per il formato dell'orario

    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';

        if (!use24HourFormat) {
            hours = hours % 12;
            hours = hours ? hours : 12; // Formato a 12 ore
        }

        const timeString = hours.toString().padStart(2, '0') + ':' +
                           minutes.toString().padStart(2, '0') + ':' +
                           seconds.toString().padStart(2, '0') + ':' +
                           milliseconds.toString().padStart(3, '0') +
                           (use24HourFormat ? '' : ' ' + ampm);

        return timeString;
    }

    function displayTime() {
        const timeContainer = $('<div id="test" aria-label="Orario corrente"></div>');
        const savedPosition = GM_getValue('timeContainerPosition');
        if (savedPosition) {
            const [top, left] = savedPosition.split(',');
            timeContainer.css({
                'position': 'fixed',
                'top': top,
                'left': left
            });
        } else {
            timeContainer.css({
                'position': 'fixed',
                'top': '10px',
                'left': '10px'
            });
        }
        timeContainer.css({
            'background': 'black',
            'padding': '5px',
            'border': '2px solid gold',
            'borderRadius': '5px',
            'fontFamily': 'Arial, sans-serif',
            'fontSize': '14px',
            'color': 'lime',
            'zIndex': '9999',
            'cursor': 'move',
            'width': '110px'
        });
        $('body').append(timeContainer);

        timeContainer.draggable({
            stop: function() {
                savePosition(timeContainer);
            }
        });

        setInterval(function() {
            timeContainer.text(getCurrentTime()); // Mostra il tempo corrente
        }, 90); // Aggiorna ogni 90 ms
    }

    function savePosition(element) {
        const top = element.css('top');
        const left = element.css('left');
        GM_setValue('timeContainerPosition', `${top},${left}`);
    }

    // Aggiunge il comando per cambiare formato
    GM_registerMenuCommand('Cambia formato orario', function() {
        use24HourFormat = !use24HourFormat;
        alert('Formato orario cambiato a ' + (use24HourFormat ? '24 ore' : '12 ore'));
    });

    GM_registerMenuCommand('Mostra/Nascondi Pulsante', function() {
        const timeContainer = $('#test');
        timeContainer && timeContainer.toggle();
    });

    displayTime();
})();