mini clock 2025figuccio

clock 2025 dragabile

  1. // ==UserScript==
  2. // @name mini clock 2025figuccio
  3. // @namespace https://greasyfork.org/users/237458
  4. // @description clock 2025 dragabile
  5. // @version 2.3
  6. // @match *://*/*
  7. // @noframes
  8. // @grant GM_addStyle
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_registerMenuCommand
  12. // @icon data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
  13. // @require http://code.jquery.com/jquery-latest.js
  14. // @require https://code.jquery.com/ui/1.13.2/jquery-ui.js
  15. // @license MIT
  16. // ==/UserScript==
  17. (function() {
  18. 'use strict';
  19. var $ = window.jQuery;
  20.  
  21. function savePosition(left, top) {
  22. GM_setValue('clockPosition', JSON.stringify({ left, top }));
  23. }
  24.  
  25. function loadPosition() {
  26. let position = GM_getValue('clockPosition');
  27. return position ? JSON.parse(position) : { left: '900px', top: '0px' };
  28. }
  29.  
  30. var clock = $('<div>', {
  31. css: {
  32. position: 'fixed',
  33. fontSize: '16px',
  34. background: '#181818',
  35. cursor: 'pointer',
  36. padding: '4px',
  37. color: 'red',
  38. border: '2px solid green',
  39. borderRadius: '5px',
  40. zIndex: '999999',
  41. textAlign: 'center'
  42. }
  43. }).text('00:00:00:000').appendTo(document.body);
  44.  
  45. function updateClock() {
  46. var now = new Date();
  47. clock.text(`${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}:${now.getMilliseconds().toString().padStart(3, '0')}`);
  48. }
  49.  
  50. setInterval(updateClock, 90);
  51.  
  52. clock.hover(function() {
  53. let currentDate = new Date();
  54. clock.attr('title', currentDate.toLocaleDateString('it', { day: '2-digit', month: 'long', weekday: 'long', year: 'numeric' }));
  55. });
  56.  
  57. $(document).ready(function() {
  58. clock.draggable({
  59. containment: 'window',
  60. stop: function(event, ui) {
  61. savePosition(ui.position.left, ui.position.top);
  62. }
  63. });
  64.  
  65. let savedPosition = loadPosition();
  66. clock.css({ left: savedPosition.left, top: savedPosition.top });
  67.  
  68. window.addEventListener('beforeunload', function() {
  69. let currentPosition = clock.position();
  70. savePosition(currentPosition.left, currentPosition.top);
  71. });
  72. });
  73.  
  74. GM_registerMenuCommand('Mostra/Nascondi Orologio', function() {
  75. clock.toggle();
  76. });
  77.  
  78. })();