Display Ora corrente con Milliseconds and AM/PM

Visualizza l'ora corrente in millisecondi e nel formato AM/PM (2024)

  1. // ==UserScript==
  2. // @name Display Ora corrente con Milliseconds and AM/PM
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 0.3
  5. // @description Visualizza l'ora corrente in millisecondi e nel formato AM/PM (2024)
  6. // @author figuccio
  7. // @match https://*/*
  8. // @grant GM_addStyle
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_registerMenuCommand
  12. // @require http://code.jquery.com/jquery-latest.js
  13. // @require https://code.jquery.com/ui/1.13.2/jquery-ui.js
  14. // @icon data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
  15. // @noframes
  16. // @license MIT
  17. // ==/UserScript==
  18. (function() {
  19. 'use strict';
  20. var $ = window.jQuery;
  21. let use24HourFormat = false; // Variabile per il formato dell'orario
  22.  
  23. function getCurrentTime() {
  24. const now = new Date();
  25. let hours = now.getHours();
  26. const minutes = now.getMinutes();
  27. const seconds = now.getSeconds();
  28. const milliseconds = now.getMilliseconds();
  29. const ampm = hours >= 12 ? 'PM' : 'AM';
  30.  
  31. if (!use24HourFormat) {
  32. hours = hours % 12;
  33. hours = hours ? hours : 12; // Formato a 12 ore
  34. }
  35.  
  36. const timeString = hours.toString().padStart(2, '0') + ':' +
  37. minutes.toString().padStart(2, '0') + ':' +
  38. seconds.toString().padStart(2, '0') + ':' +
  39. milliseconds.toString().padStart(3, '0') +
  40. (use24HourFormat ? '' : ' ' + ampm);
  41.  
  42. return timeString;
  43. }
  44.  
  45. function displayTime() {
  46. const timeContainer = $('<div id="test" aria-label="Orario corrente"></div>');
  47. const savedPosition = GM_getValue('timeContainerPosition');
  48. if (savedPosition) {
  49. const [top, left] = savedPosition.split(',');
  50. timeContainer.css({
  51. 'position': 'fixed',
  52. 'top': top,
  53. 'left': left
  54. });
  55. } else {
  56. timeContainer.css({
  57. 'position': 'fixed',
  58. 'top': '10px',
  59. 'left': '10px'
  60. });
  61. }
  62. timeContainer.css({
  63. 'background': 'black',
  64. 'padding': '5px',
  65. 'border': '2px solid gold',
  66. 'borderRadius': '5px',
  67. 'fontFamily': 'Arial, sans-serif',
  68. 'fontSize': '14px',
  69. 'color': 'lime',
  70. 'zIndex': '9999',
  71. 'cursor': 'move',
  72. 'width': '110px'
  73. });
  74. $('body').append(timeContainer);
  75.  
  76. timeContainer.draggable({
  77. stop: function() {
  78. savePosition(timeContainer);
  79. }
  80. });
  81.  
  82. setInterval(function() {
  83. timeContainer.text(getCurrentTime()); // Mostra il tempo corrente
  84. }, 90); // Aggiorna ogni 90 ms
  85. }
  86.  
  87. function savePosition(element) {
  88. const top = element.css('top');
  89. const left = element.css('left');
  90. GM_setValue('timeContainerPosition', `${top},${left}`);
  91. }
  92.  
  93. // Aggiunge il comando per cambiare formato
  94. GM_registerMenuCommand('Cambia formato orario', function() {
  95. use24HourFormat = !use24HourFormat;
  96. alert('Formato orario cambiato a ' + (use24HourFormat ? '24 ore' : '12 ore'));
  97. });
  98.  
  99. GM_registerMenuCommand('Mostra/Nascondi Pulsante', function() {
  100. const timeContainer = $('#test');
  101. timeContainer && timeContainer.toggle();
  102. });
  103.  
  104. displayTime();
  105. })();
  106.