Clock figuccio

clock ore minuti secondi millesimi data

// ==UserScript==
// @name          Clock figuccio
// @description   clock ore minuti secondi millesimi data
// @version        2.7
// @match          *://*/*
// @noframes
// @author        figuccio
// @grant         GM_setValue
// @grant         GM_getValue
// @grant         GM_registerMenuCommand
// @icon          data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
// @namespace     https://greasyfork.org/users/237458
// @require       http://code.jquery.com/jquery-latest.js
// @require       https://code.jquery.com/ui/1.12.1/jquery-ui.js
// @license        MIT
// ==/UserScript==

var $ = window.jQuery;
var j = $.noConflict();

const body = document.body;

// Funzione per aggiornare l'orologio
function updateClock() {
    var data = new Date().toLocaleString('it', {'day':'2-digit','year':'numeric','month':'long','weekday':'long'});
    document.getElementById('Clocktest').innerHTML = data;
}

// Crea nodo orologio
var clockNode = document.createElement('div');
clockNode.id = "Clocktest";
clockNode.title = 'click time';
clockNode.setAttribute("style","cursor:move;padding:4px;background:black;color:lime;font-family: Orbitron;letter-spacing: 2px;top:0;font-size:14px;position:fixed;text-align:center;z-index:999999;border-radius:10px;border:2px solid red;");
document.body.appendChild(clockNode);
setInterval(updateClock, 1000);
j(clockNode).draggable();
body.append(clockNode);

// Funzione per aggiornare l'ora dell'orologio
function Clock() {
    var date = new Date();
    var mm = new Date().getMilliseconds();
    var ore = date.toLocaleString('it', {
    hour:'2-digit',minute:'numeric',second:'numeric',
    });
    document.getElementById('b').innerHTML = ore + ":" + mm;
}

// Crea nodo temporale
var timeNode = document.createElement('div');
timeNode.id = "b";
timeNode.title = 'trascina time+click data';
timeNode.setAttribute("style","cursor:move;padding:4px;background:black;color:lime;top:0px;font-family:sans-serif;font-size:14px;position:fixed;text-align:center;z-index:999999;border-radius:10px;border:2px solid yellow;");
document.body.appendChild(timeNode);
setInterval(Clock, 70);
j(timeNode).draggable();
body.append(timeNode);

// Funzione per alternare tra orologio e nodi temporali
function toggleNodes() {
    if (clockNode.style.display === 'none') {
        clockNode.style.display = 'block';
        timeNode.style.display = 'none';
    } else {
        clockNode.style.display = 'none';
        timeNode.style.display = 'block';
    }
}

// Attiva/disattiva i nodi al clic
timeNode.addEventListener("click", toggleNodes);
clockNode.addEventListener("click", toggleNodes);

// Inizialmente nascondi l'orologio
clockNode.style.display = 'none';

// Salva la posizione quando i nodi vengono trascinati
j(clockNode).on("dragstop", function(event, ui) {
    GM_setValue('clock_position', { x: ui.position.left, y: ui.position.top });
});

j(timeNode).on("dragstop", function(event, ui) {
    GM_setValue('time_position', { x: ui.position.left, y: ui.position.top });
});

// Ripristina le posizioni quando la pagina si ricarica
var clockPosition = GM_getValue('clock_position', { x: 0, y: 0 });
var timePosition = GM_getValue('time_position', { x: 0, y: 0 });

j(clockNode).css({ left: clockPosition.x, top: clockPosition.y });
j(timeNode).css({ left: timePosition.x, top: timePosition.y });