clock 2024 dragabile
当前为
// ==UserScript==
// @name mini clock 2020figuccio
// @namespace https://greasyfork.org/users/237458
// @description clock 2024 dragabile
// @version 1.9
// @match *://*/*
// @noframes
// @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.12.1/jquery-ui.js
// @license MIT
// ==/UserScript==
let $ = window.jQuery;
const body = document.body;
let div, spn;
function createClock() {
div = $('<div id="us_MiniClock">').css({
'position': 'fixed',
'top': '0px',
'right': '0',
'cursor': 'pointer',
'width': '90px',
'color': 'red',
'background-color': '#181818',
'border': '2px solid green',
'padding': '1px 7px',
'font': '13pt normal sans-serif',
'z-index': '2147483647'
});
spn = $('<span>').appendTo(div);
div.draggable(); // Rendi l'elemento draggable
div.mouseenter(function() {
let currentDate = new Date();
div.attr('title', currentDate.toLocaleDateString('it', {day:'2-digit', month:'long', weekday:'long', year:'numeric'}));
});
body.appendChild(div[0]);
}
function initClock() {
createClock();
setInterval(updateClock, 100);
addContextMenu();//serve
}
function updateClock() {
const date = new Date();
spn.text(date.toLocaleTimeString('it', {hour12:false, hour:'2-digit', minute:'2-digit', second:'2-digit', fractionalSecondDigits: 3}));
}
///////////mostra/nascondi orologio
function addContextMenu() {
if (typeof GM_registerMenuCommand === 'function') {
GM_registerMenuCommand('Mostra/Nascondi orologio', function() {
div.toggle();
});
}
}
//////////
initClock();
//////////////////////local storage posizione
// Dichiarazione di variabile per salvare la posizione
let savedPosition = GM_getValue('savedPosition');
// Se c'è una posizione salvata, imposta l'elemento alla posizione salvata
if (savedPosition) {
let [left, top] = savedPosition.split(',');
div.css({ 'left': left + 'px', 'top': top + 'px' });
}
// Aggiungi un evento per salvare la posizione quando l'elemento viene trascinato
div.on('dragstop', function(event, ui) {
let position = ui.position;
GM_setValue('savedPosition', position.left + ',' + position.top);
});