mini clock 2020figuccio

clock 2024 dragabile

当前为 2024-03-10 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         mini clock 2020figuccio
// @namespace    https://greasyfork.org/users/237458
// @description  clock 2024 dragabile
// @version      2.1
// @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.12.1/jquery-ui.js
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';
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, 80);
    addContextMenu();//serve
}

function updateClock() {
const d = new Date();
const t = d.toLocaleTimeString();
const mm = d.getMilliseconds();//millisecondi settembre 2023
document.getElementById("us_MiniClock").innerHTML =t +":"+ mm;
}
///////////mostra/nascondi orologio
function addContextMenu() {
    if (typeof GM_registerMenuCommand === 'function') {
        GM_registerMenuCommand('Mostra/Nascondi orologio', function() {
            div.toggle();
        });
    }
}
//////////
initClock();
// Aggiungi un evento per trascinare l'elemento limitato allo schermo
div.draggable({
    containment: "window"
});

//////////////////////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);
});
})();