Clock2

Show time drag

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Clock2
// @description Show time drag
// @author      figuccio
// @version     0.4
// @namespace   https://greasyfork.org/users/237458
// @match       *://*/*
// @grant       GM_addStyle
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_registerMenuCommand
// @require     https://code.jquery.com/jquery-3.6.0.min.js
// @require     https://code.jquery.com/ui/1.12.1/jquery-ui.js
// @icon        https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @license     MIT
// ==/UserScript==
(function() {
    'use strict';
    // Imposta jQuery a $ per evitare conflitti con altre librerie
    var $ = window.jQuery;

    // Estende il prototipo del numero per aggiungere un metodo di padding
    Number.prototype.pad = function(size) {
        if (typeof(size) !== "number") {
            size = 2;
        }
        var s = String(this);
        while (s.length < size) {
            s = "0" + s;
        }
        return s;
    }

    // Crea un elemento div per visualizzare l'orologio
    var tod = $('<div>').attr({
        id: 'todClock',
        style: 'color:black; font-family:droid sans mono; font-size:16pt; line-height:20px; position:fixed; text-align:center; z-index:99999999999; background-color:green; -moz-user-select:none; cursor:move;'
    }).draggable({
        containment: "window" // Limita il drag alla finestra
    });

    // Aggiorna l'orologio ogni secondo
    function tick() {
        var d = new Date();
        var Y = d.getFullYear();
        var M = (d.getMonth() + 1).pad();
        var D = d.getDate().pad();
        var h = d.getHours().pad();
        var m = d.getMinutes().pad();
        var s = d.getSeconds().pad();
        var ms = d.getMilliseconds();
        tod.html(h + ":" + m + ":" + s + ":" + ms + "-" + D + "/" + M + "/" + Y);

        // Salva la posizione dell'orologio nel localStorage
        var position = tod.position();
        GM_setValue("clock_position", position);
    }

    // Ripristina la posizione salvata dell'orologio
    function restoreClockPosition() {
        var savedPosition = GM_getValue("clock_position");
        if (savedPosition) {
            tod.css({
                top: savedPosition.top,
                left: savedPosition.left
            });
        }
    }

    // Mostra o nasconde l'orologio
    function toggleClock() {
        tod.toggle();
    }

    // Registra il comando di menu per mostrare/nascondere l'orologio
    GM_registerMenuCommand("Mostra/Nascondi Clock", toggleClock);

    // Aggiungi l'orologio al corpo della pagina e avvia l'aggiornamento
    $(document.body).append(tod);
    restoreClockPosition();
    tick();
    setInterval(tick, 70);

})();